0

Python と opencv3 を使用して、ライブ ストリームで最大の画像の輪郭を描きました。コードが間違っていたようです。誰か助けてください。

import cv2,platform
import numpy as np

def larger(x):
    gray = cv2.cvtColor(x, cv2.COLOR_BGR2GRAY)
    image = cv2.Canny(gray,35,200)
    (_,cnts,_) = cv2.findContours(image.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
    c = max(cnts, key=cv2.contourArea)
    return cv2.minAreaRect(c)
capture = cv2.VideoCapture(0)
retval, im = capture.read()
y = larger(im)
box = np.int0(cv2.boxPoints(y))
cv2.drawContours(im,[box],-1,(0,255,0),2)
cv2.imshow("Image",im)
cv2.waitKey(0)
cv2.destroyAllWindows()

このコードには 2 つの問題があります。

1) is my web cam was on but cant see any video image, getting this error

    "Traceback (most recent call last):
      File "C:\Users\Snehith\Desktop\project vision\cnt.py", line 14, in <module>
        y = larger(im)
      File "C:\Users\Snehith\Desktop\project vision\cnt.py", line 8, in larger
        c = max(cnts, key=cv2.contourArea)
    ValueError: max() arg is an empty sequence"
2) i want a continuous video stream along with the contour, please explain the mistakes and also solutions in python and opencv 
4

1 に答える 1