Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在opencv中显示轮廓或形态变化的图像_Python_Image_Opencv - Fatal编程技术网

Python 如何在opencv中显示轮廓或形态变化的图像

Python 如何在opencv中显示轮廓或形态变化的图像,python,image,opencv,Python,Image,Opencv,这是我的代码,我想看到最终的轮廓图像与矩圆,但当我givve img = cv2.imread("/Users/meenakshi/Desktop/lala.jpg") img=cv2.resize(img,(1200,700)) gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) binary = cv2.inRange(gray,65,255) image,contours,hierarchy = cv2.findContours(binary.copy(

这是我的代码,我想看到最终的轮廓图像与矩圆,但当我givve

img = cv2.imread("/Users/meenakshi/Desktop/lala.jpg")
img=cv2.resize(img,(1200,700))
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
binary = cv2.inRange(gray,65,255)
image,contours,hierarchy = cv2.findContours(binary.copy(),cv2.RETR_TREE,cv2.CHAIN_APPROX_NONE)
cnt = max(contours, key= lambda x: cv2.contourArea(x))
cv2.imshow("Radar", cnt)
cv2.waitKey(0)
epsilon = 0.0005*cv2.arcLength(cnt,True)
cnt = cv2.approxPolyDP(cnt,epsilon,True)
M = cv2.moments(cnt)
cX = int(M["m10"]/M["m00"])
cY = int(M["m01"]/M["m00"])
cv2.circle(cnt,(cX,cY),7,(0,255,0),-1)
错误显示为

cv2.imshow("Image", cnt)
cv2.waitKey(0)
我该怎么办

cv2.圆(cnt,(cX,cY),7,(0255,0),-1)

用最大面积在轮廓上创建一个圆。 如果你想在原始图像上看到一个圆,你可以通过img而不是cnt

(-15:Bad number of channels) Source image must have 1, 3 or 4 channels in function 'cvConvertImage'
cv2.圆(cnt,(cX,cY),7,(0255,0),-1)

用最大面积在轮廓上创建一个圆。 如果你想在原始图像上看到一个圆,你可以通过img而不是cnt

(-15:Bad number of channels) Source image must have 1, 3 or 4 channels in function 'cvConvertImage'

打印
cnt.shape
并查看它有多少通道。然后找出原因。另一种选择是将所有的
import
语句和缺少的代码放回原处,并共享您的图像,以便folk可以为您提供帮助。打印
cnt.shape
并查看它有多少频道。然后找出原因。另一种选择是将所有的
import
语句和缺少的代码放回原处,并共享您的图像,以便folk可以帮助您。