我不知道如何去探测所有的岩石。我能发现一些岩石。有些岩石是黑色的我无法察觉。
import numpy as np
import cv2
def nothing(x):
pass
H_Max= 169
H_Min=147
S_Max=103
S_Min=19
V_Max=199
V_Min=139
while True:
name_pic='153.jpg'
img = cv2.imread(name_pic)
frame = cv2.imread(name_pic)
img = cv2.resize(img, (1500, 1000))
frame = cv2.resize(frame, (1500, 1000))
blurred = cv2.GaussianBlur(frame, (5, 5), 0)
hsv = cv2.cvtColor(blurred, cv2.COLOR_BGR2HSV)
mask = cv2.inRange(hsv, (H_Min, S_Min, V_Min), (H_Max, S_Max, V_Max))
kernel = np.ones((5,5), np.uint8)
frame_out, contours, hierarchy = cv2.findContours(
mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
for cnt in contours:
M = cv2.moments(cnt)
if M['m00'] == 0 :
M['m00'] = 0.1
cx = int(M['m10'] / M['m00'])
cy = int(M['m01'] / M['m00'])
area = cv2.contourArea(cnt)
if area < 2.5 :
continue
x, y, w, h = cv2.boundingRect(cnt)
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 0, 255), 2)
cv2.imshow('frame1',frame)
cv2.imshow('fimg', img)
key = cv2.waitKey(1) & 0xFF
if key == 27:
break
cv2.destroyAllWindows()
我不知道如何改善我的检测。
谢谢
这是处理前后的图片。
检测前:
检测后: