-1

I am reading a video here:

VideoCap = cv2.VideoCapture("E:\Omar's Stuff\College related\Forth Year\Project\Kalman Filter 
                                                                      code\video_randomball.avi")
ret, frame = VideoCap.read()

and sending the frames to a detect function here:

# Detect object
centers = detect(frame,debugMode)

trying to convert here:

def detect(frame,debugMode): # Convert frame from BGR to GRAY #frame = frame.astype('uint8') gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

and getting this error:

OpenCV(3.4.2) c:\projects\opencv-python\opencv\modules\imgproc\src\color.hpp:253: error: (-215:Assertion failed) VScn::contains(scn) && VDcn::contains(dcn) && VDepth::contains(depth) in function 'cv::CvtHelper<struct cv::Set<3,4,-1>,struct cv::Set<1,-1,-1>,struct cv::Set<0,2,5>,2>::CvtHelper'

how to fix it?

AbdelAziz AbdelLatef
  • 3,650
  • 6
  • 24
  • 52
Omar Sobhy
  • 29
  • 4

1 Answers1

0

Something wrong with the video file path that you have passed in cv2.VideoCapture() method so try to correct the path and if not able to correct then simply drag and drop the video file along with the python script folder then it will work.

Here is sample code to read the video in the same directory where the python script is located

import cv2
import numpy as np

# Create a VideoCapture object and read from input file
cap = cv2.VideoCapture('tree.mp4')

# Check if camera opened successfully
if (cap.isOpened()== False):
print("Error opening video file")

# Read until video is completed
while(cap.isOpened()):
    
# Capture frame-by-frame
ret, frame = cap.read()
if ret == True:

    # Display the resulting frame
    cv2.imshow('Frame', frame)

    # Press Q on keyboard to exit
    if cv2.waitKey(25) & 0xFF == ord('q'):
    break

# Break the loop
else:
    break

# When everything done, release
# the video capture object
cap.release()

# Closes all the frames
cv2.destroyAllWindows()
beaker
  • 16,331
  • 3
  • 32
  • 49
Mohit Verma
  • 56
  • 1
  • 6