我已经阅读了https://www.pyimagesearch.com/2015/11/02/watershed-opencv/教程,这让我惊讶地发现了这种惊人的可能性,现在我正在尝试将其实现到当前的对象跟踪程序中。我正在努力将这种算法实现到我的项目中,因为它需要视频流,并且还创建了一个只能看到红色物体的遮罩。该程序的主要问题是重叠的对象被视为一个对象,而在阅读了本教程之后,我意识到有一个针对该对象的算法,但是我无法弄清楚如何将其实现到我的项目中。
任何人都可以分享一些见识,并希望称我为白痴,并让我睁开眼睛。
我感谢任何评论。非常感谢你
我一直关注的教程/研究 https://www.pyimagesearch.com/2015/11/02/watershed-opencv/ Image Segmentation using Mean Shift explained https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_imgproc/py_watershed/py_watershed.html
# This is my main functionality in my code. And I have no idea where I can implement
# watershed succesfully because of the color filtering and constant background change
while True:
frame = camera.read() # read camera
if frame is None:
print('fail with camera. Is it being used? src # correct?')
break
frame = imutils.resize(frame, width=400) # resize frame
height = np.size(frame, 0) # calculates the height of frame
width = np.size(frame, 1) # calculates the width of frame
blurred = cv2.GaussianBlur(frame, (21, 21), 0) # blurring image before hsv applied (less noise)
hsv = cv2.cvtColor(blurred, cv2.COLOR_BGR2HSV) # creating hsv from blurred frame and converting the bgr to hsv
mask = cv2.inRange(hsv, np.array(args["a"]), np.array(args["b"])) # mask is setting hsv in range of the lower and upper blue ranges
mask = cv2.erode(mask, None, iterations=2) # erode for less noise / more white
mask = cv2.dilate(mask, None, iterations=2) # dilate does similar but makes whiteness thicker
res = cv2.bitwise_and(frame, frame, mask=mask)
contours = cv2.findContours(mask.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) # find contours of mask
contours = imutils.grab_contours(contours) # get them
middleLine = (height / 2) # calculate the middleLine
cv2.line(frame, (0, height // 2), (width, height // 2), (100, 200, 100), 2) # // = int division | draw the line
rects = []
if len(contours) > 0: # don't pass in empty contour!!!
for c in contours: # loop through them
if cv2.contourArea(c) < args["e"]: # not big enough to be considered an object
continue # go next
(x, y, w, h) = cv2.boundingRect(c) # create rect for the object
我希望能够计算一个分水岭算法,以便能够唯一地识别重叠在具有彩色滤镜的网络摄像头流上的对象,但是如果您愿意,我遵循的教程始终将我留在“ cliffhanger”上因为他们使用的方法适用于图像而不适用于视频,并且它们没有颜色过滤功能,所以我似乎无法获得使它适用于视频流和颜色过滤项目所需的图片。