如何修改这个python opencv程序来从阈值图像中获取xy坐标

How to modify this python opencv program to get xy coordinates from thresholded image

本文关键字:阈值 图像 坐标 xy 获取 程序 opencv 何修改 修改 python      更新时间:2023-10-16

我有一个opencv程序来跟踪一个蓝色的对象

有人可以修改它,找到从摄像头跟踪的对象的中心阈值后,它的二值图像

PS:我希望这个程序与网络摄像头一起工作,而不是图像

import numpy as np
import cv2
cap = cv2.VideoCapture(1)
while(True):
ret, frame = cap.read()  
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
lower_blue = np.array([110,50,50])
upper_blue = np.array([130,255,255])
mask = cv2.inRange(gray, lower_blue, upper_blue)
res = cv2.bitwise_and(frame,frame, mask= mask)
# Display the resulting frame
cv2.imshow('frame',gray)
cv2.imshow('mask',mask)
cv2.imshow('res',res)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()

我想从网络摄像头的阈值图像中找到白色斑点的中心xy坐标

我有代码,我用来寻找阈值图像的xy坐标

我想修改它从网络摄像头的实时视频

下面是查找二进制图像坐标的代码

for y in xrange(img.size[1]):
for x in xrange(img.size[0]):
if pixels[x, y] == 0:
xlist.append(x)
ylist.append(y)
xleft = min(xlist)
xright = max(xlist)
ytop = min(ylist)
ybot = max(ylist)
xax = (xleft+xright)/2
yax = (ytop+ybot)/2

有人能把这两个代码结合起来,使它可以从网络摄像头的实时饲料

你想在bitwise_and之后找到contours,然后获得轮廓的boundingRect(或矩)以获得x,y位置。

,忘记你的"查找二值图像的坐标"的想法。(不,你不想要重新发明"连接组件"。使用内置的东西代替)