Imread Returns None, Violating Assertion !_Src.Empty() in Function 'Cvtcolor' Error

imread returns None, violating assertion !_src.empty() in function 'cvtColor' error

This error happened because the image didn't load properly. So you have a problem with the previous line cv2.imread. My suggestion is :

  • check if the image exists in the path you give

  • check if the count variable has a valid number

OpenCV (4.1.2) error !_src.empty() in function 'cvtColor'

This is what happens when None is passed to cv2.cvtColor()

After attempting to open and read an image, check that it worked.

img = cv2.imread(path, cv2.IMREAD_COLOR)
if img is not None:
# Didn't work; do something here.

Video frame returning !_src.empty() in function 'cvtColor' error

You will have to read the frame before performing any conversion.

Move the part

        //Capture frame by frame
bool success = cap.read(frame);

//If frame is empty then break the loop
if (!success){
std::cout << "Found the end of the video" << std::endl;
break;
}

Just after

        cv::Mat frame;

Why do I get the following error after and hour of operation cv2.error:(-215:Assertion failed) !src.empty() in function 'cvtColor'

I have added if(ret == True): to the following and there have been no errors for six hours:

ret, img = cap.read()
if(ret == True):
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
for (x, y, w, h) in faces:
cv2.rectangle(img, (x, y), (x + w, y + h), (255, 255, 0), 2)
roi_gray = gray[y:y + h, x:x + w]
roi_color = img[y:y + h, x:x + w]
if(h):
print("active")
print(ret)
activityScan("active",c)
else:
print("inactive")
print(ret)
activityScan("inactive",c)


Related Topics



Leave a reply



Submit