cv2.inRange (python 2.7)로 색상을 기반으로 객체 감지를 수행하려고합니다. BGR 색상을 사용할 때 모든 것이 잘 작동하는 것 같습니다. 그러나, 내가 HSV에 BGR 색상을지도, 내가 올바른 마스크를 얻을 수 없습니다. opencv - python - cv2.inRange에서 HSV 색상을 사용할 때 혼란 스럽습니다.
# first convert the img, and the associated lower and upper bound to HSV
hsv_img_test = cv2.cvtColor(img_test, cv2.COLOR_BGR2HSV)
lower_hsv = cv2.cvtColor(np.uint8([[[b-step,g-step,r-step]]]), cv2.COLOR_BGR2HSV)
upper_hsv = cv2.cvtColor(np.uint8([[[b+step,g+step,r+step]]]), cv2.COLOR_BGR2HSV)
plt.figure(figsize=(20,10))
plt.subplot(1,2,1)
plt.imshow(cv2.cvtColor(hsv_img_test, cv2.COLOR_BGR2RGB))
# apply threshold on hsv image
mask = cv2.inRange(hsv_img_test, lower_hsv, upper_hsv)
plt.subplot(1,2,2)
plt.imshow(mask, cmap='gray')
HSV
에 BGR
img_test = cv2.imread("test_img/mario.jpeg")
#define color range for object detection
step = 10
r,g,b = 203, 31, 25 #red
lower_bgr = np.uint8([b-step, g-step, r-step])
upper_bgr = np.uint8([b + step, g + step, r + step])
# plot mario in BGR and corresponding mask
plt.figure(figsize=(20,10))
plt.subplot(1,2,1)
plt.imshow(cv2.cvtColor(img_test, cv2.COLOR_BGR2RGB))
mask = cv2.inRange(img_test, lower_bgr, upper_bgr)
plt.subplot(1,2,2)
plt.imshow(mask, cmap='gray')
2) 임계 값 (제대로 작동하지 않는에서
1) 임계 값) .. : 아래의 예를 참조하십시오 . 그것은 분명히 정확하지 않습니다. 코드에서 무엇이 잘못되었는지 파악할 수 없으며, 어떤 도움을 주시면 감사하겠습니다!
'target_color_h '가 서명 된 유형 일 때 작동합니다. 저장면에 있기 위해'max (tolerance, target_color_h) - tolerance'를 사용할 수 있습니다. – Kjell