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
Find and Replace String Values in List
How to Verify If One List Is a Subset of Another
How to Insert a Column at a Specific Column Index in Pandas
How to Sandbox Python in Pure Python
Find_Element_By_* Commands Are Deprecated in Selenium
Numpy Array Assignment with Copy
Windows Cmd Encoding Change Causes Python Crash
How to Set Environment Variables in Pycharm
Maximum Value for Long Integer
Replacing Few Values in a Pandas Dataframe Column with Another Value
List to Dictionary Conversion with Multiple Values Per Key
Differencebetween Contiguous and Non-Contiguous Arrays
How to Convert a Dataframe to a Dictionary
How to Pass a Method as a Parameter in Python
"Cannot Open Include File: 'Config-Win.H': No Such File or Directory" While Installing MySQL-Python
How to Scroll the Background Surface in Pygame
How to Make Program Go Back to the Top of the Code Instead of Closing