0

OS: Win7 Python version: updated (3.8.1) So the thing is, by using OpenCV module , I'm trying to access the inbuilt webcam of my laptop to capture the video & process the frames, but the window displating the real-time video is not showing up despite the indicator light of the webcam turning on implying the webcam is working, and the following error is being encountered:

Traceback (most recent call last): File:............. line 8, in gray = cv2.cvtColor(diff, cv2.COLOR_RGB2GRAY) cv2.error: OpenCV(4.5.5) D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'> Blockquote

Here's the code snippet:

import cv2
import winsound
cam = cv2.VideoCapture(0) 
while cam.isOpened():
    ret, frame1 = cam.read()
    ret, frame2 = cam.read()
    diff = cv2.absdiff(frame1, frame2)
    gray = cv2.cvtColor(diff, cv2.COLOR_RGB2GRAY)
RA 212
  • 1
  • always the same, `assert cam.isOpened()` right after its creation, and `if not ret: break` after each read – Christoph Rackwitz Apr 27 '22 at 07:57
  • 2
    Does this answer your question? [OpenCV VideoCapture and error: (-215:Assertion failed) !\_src.empty() in function 'cv::cvtColor'](https://stackoverflow.com/questions/54121013/opencv-videocapture-and-error-215assertion-failed-src-empty-in-function) – Christoph Rackwitz Apr 27 '22 at 08:01
  • Change this: grey = cv2.cvtColor(d, cv2.COLOR_BGR2GRAY) – toyota Supra Apr 28 '22 at 01:41

0 Answers0