P
P
Ping Wins2019-02-28 09:19:35
Python
Ping Wins, 2019-02-28 09:19:35

OpenCV throws an error when starting. How to fix?

I have this code

import numpy as np
import cv2
import time

faceCascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')

cap = cv2.VideoCapture(1)
cap.set(3,640) 
cap.set(4,480)

while True:
    ret, img = cap.read()
    faces = faceCascade.detectMultiScale(
        scaleFactor = 1.2,
        minNeighbors = 5,
        minSize = (50,50)
    )

    for (x,y,w,h) in faces:
        cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
        roi_color = img[y:y+h, x:x+w]

    cv2.imshow('video',img)

    k = cv2.waitKey(30) & 0xff
    if k == 27: # нажми 'ESC' для выхода
        break

cap.release()
cv2.destroyAllWindows()

It gives me an error:
VIDEOIO ERROR: V4L: can't open camera by index 1
Traceback (most recent call last):
  File "OpenCV.py", line 16, in <module>
    minSize = (50,50)
TypeError: Required argument 'image' (pos 1) not found

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question