gpt4 book ai didi

python - TypeError : src is not a numpy array, 既不是标量。无流

转载 作者:太空宇宙 更新时间:2023-11-03 22:46:26 26 4
gpt4 key购买 nike

import cv2
import numpy as np
cam = cv2.VideoCapture('tcp://192.168.1.1:5555')
img_gray = cv2.cvtColor(cam,cv2.COLOR_BGR2GRAY)
ret, thresh = cv2.threshold(img_gray, 127, 255,0)
contours,hierarchy = cv2.findContours(thresh,2,1)
cnt = contours[0]

hull = cv2.convexHull(cnt,returnPoints = False)
defects = cv2.convexityDefects(cnt,hull)

for i in range(defects.shape[0]):
s,e,f,d = defects[i,0]
start = tuple(cnt[s][0])
end = tuple(cnt[e][0])
far = tuple(cnt[f][0])
cv2.line(img,start,end,[0,255,0],2)
cv2.circle(img,far,5,[0,0,255],-1)

cv2.imshow('img',cam)
cv2.waitKey(0)
cv2.destroyAllWindows()

当从我的无人机流式传输以检测排水沟的轮廓时,我试图找到轮廓,但我收到此错误。我不确定如何修复它。任何帮助将不胜感激。

最佳答案

import cv2
import numpy as np

cam = cv2.VideoCapture('tcp://192.168.1.1:5555')
if not cam.isOpened():
print("VideoCapture failed to open")

while True:
ret, frame = cam.read()

if ret == False:
print("frame empty")
break

img_gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
ret, thresh = cv2.threshold(img_gray, 127, 255,0)
contours,hierarchy = cv2.findContours(thresh,2,1)
cnt = contours[0]

hull = cv2.convexHull(cnt,returnPoints = False)
defects = cv2.convexityDefects(cnt,hull)

for i in range(defects.shape[0]):
s,e,f,d = defects[i,0]
start = tuple(cnt[s][0])
end = tuple(cnt[e][0])
far = tuple(cnt[f][0])
cv2.line(img,start,end,[0,255,0],2)
cv2.circle(img,far,5,[0,0,255],-1)

cv2.imshow('img',frame)
cv2.waitKey(0)

cv2.destroyAllWindows()

我认为你可以做这样的事情来解决你的代码的问题。

关于python - TypeError : src is not a numpy array, 既不是标量。无流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46503906/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com