P
P
Ping Wins2019-08-22 05:09:38
Python
Ping Wins, 2019-08-22 05:09:38

What's wrong with OpenCV?

when I run the code, it gives the following error:

VIDEOIO ERROR: V4L2: Pixel format of incoming image is unsupported by OpenCV
Unable to stop the stream: Device or resource busy
OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /home/pi/opencv/opencv-3.4.0/modules/imgproc/src/color.cpp, line 11111
  File "OpenCV.py", line 36, in main
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.error: /home/pi/opencv/opencv-3.4.0/modules/imgproc/src/color.cpp:11111: error: (-215) scn == 3 || scn == 4 in function cvtColor

Here is part of the code
import numpy as np
import cv2

faceCascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')# Файл с характеристиками определения лица

cap = cv2.VideoCapture(0)#Запись видео
cap.set(3,640) # ширина
cap.set(4,480) # высота


while True:
        ret, img = cap.read() #Чтение видео
        try:
            gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
            #Настройка распознования лица
            faces = faceCascade.detectMultiScale(
                gray,
                scaleFactor=1.2,
                minNeighbors=5,
                minSize=(20, 20))

        except:
            cap.release()
            raise

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