TypeError: VideoCapture() takes no arguments
时间: 2024-05-05 21:15:15 浏览: 127
The error message "TypeError: VideoCapture() takes no arguments" means that you are trying to pass an argument to the VideoCapture() function, but it does not take any arguments.
In OpenCV, the VideoCapture() function is used to capture video from a camera or a file. It is called without any arguments to capture video from the default camera, or with a filename argument to capture video from a file.
Here is an example of how to use VideoCapture() to capture video from a camera:
```
import cv2
cap = cv2.VideoCapture(0)
while True:
ret, frame = cap.read()
cv2.imshow('frame', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
```
In this example, VideoCapture() is called with the argument 0 to capture video from the default camera. The captured video is displayed in a window using imshow(), and the loop continues until the user presses the 'q' key.
If you want to capture video from a file, you can call VideoCapture() with the filename argument:
```
import cv2
cap = cv2.VideoCapture('video.mp4')
while True:
ret, frame = cap.read()
cv2.imshow('frame', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
```
In this example, VideoCapture() is called with the filename 'video.mp4' to capture video from a file. The rest of the code is the same as in the previous example.
阅读全文