OpenCV Error: 215:Assertion failed) !_src.empty() in function 'cv::cvtColor'

190 Views Asked by At

I do not use to work with python, and I a need your help. This is my code:

import cv2
from cvzone.PoseModule import PoseDetector

cap = cv2.VideoCapture('Video.mp4')

detector = PoseDetector()
posList = []
while True:
    success, img = cap.read()
    img = detector.findPose(img)                        /*Here is the error*/
    lmList, bboxInfo = detector.findPosition(img)

    if bboxInfo:
        lmString = ''
        for lm in lmList:
            lmString += f'{lm[1]},{img.shape[0] - lm[2]},{lm[3]},'
        posList.append(lmString)

    print(len(posList))

    cv2.imshow("Image", img)
    key = cv2.waitKey(1)
    if key == ord('s'):
        with open("AnimationFile.txt", 'w') as f:
            f.writelines(["%s\n" % item for item in posList])

The error is: 215:Assertion failed) !_src.empty() in function 'cv::cvtColor'

I've read some forums, but I could't find a solution

I try with:

if img is not None: 

and

import cv2
from cvzone.PoseModule import PoseDetector

cap = cv2.VideoCapture('Video.mp4')

detector = PoseDetector()
posList = []
while True:
    success, img = cap.read()
    if not success:
        print("Can't receive frame (stream end?). Exiting ...")
        break
    img = detector.findPose(img)
    lmList, bboxInfo = detector.findPosition(img)
0

There are 0 best solutions below