face_recognition icon indicating copy to clipboard operation
face_recognition copied to clipboard

cv2.error: OpenCV(4.1.0) C:\projects\opencv-python\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'

Open rezabrg opened this issue 5 years ago • 123 comments

  • face_recognition version:4.1.0
  • Python version:3.7
  • Operating System:windows 10

Description

I'm having problem to run this program, the error under below Capture

gray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY) cv2.error: OpenCV(4.1.0) C:\projects\opencv-python\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'

What I Did

Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.

rezabrg avatar Sep 17 '19 18:09 rezabrg

i have the same problem

rafaelpsimoes avatar Oct 24 '19 20:10 rafaelpsimoes

This a secondary error that basically just means the image you are trying to process didn't load and was empty.

If you grabbed the image dara from the camera, it means the camera connection failed or isn't configured correctly. If you loaded an image file, it means the loading failed.

ageitgey avatar Oct 24 '19 20:10 ageitgey

I was facing this issue and by removing special characters from the image_file_name the issue was resolved.

Example: Renaming "48172454-thymianblätter.jpg" to "48172454-thymian.jpg".

tarvihafatima avatar Nov 12 '19 11:11 tarvihafatima

I am using hik vision's camera and i am getting same error...i think my laptop's processor is not able to load the frames due to very high resolution and frame rate

yashpatel7025 avatar Dec 12 '19 11:12 yashpatel7025

I am having the same issue. Is image resolution causing the problem?

dinezh256 avatar Dec 20 '19 05:12 dinezh256

I have same problem. My old code is : cap = cv2.VideoCapture(1)

Then I change my code, and problem has solved. Probably, opencv accepts my finger print input as a camera. Thus, I change VideoCapture parameter as follows: cap = cv2.VideoCapture(0)

ghost avatar Dec 25 '19 18:12 ghost

how to solve this error. anyone has answer for this error: OpenCV(4.1.0) C:\projects\opencv-python\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'

vijaypearl avatar Jan 24 '20 07:01 vijaypearl

this problem occcurs when you dont declare what 'im' is or the image has not been loaded to the variable 'im'/. if you're using your webcam to capture then use cap = cv2.VideoCapture(-1) on linux cap = cv2.VideoCapture(0) on windows and 'im' must be ret, im = cap.read(). So it will read the image properly. if you do follow these steps the error must not occur.

nikhilsupertramp avatar Jan 26 '20 04:01 nikhilsupertramp

Now I guess we can close this issue. @ageitgey @rezabrg @rafaelpsimoes

nikhilsupertramp avatar Jan 26 '20 04:01 nikhilsupertramp

@rezabrg download the required haarcascades it will work https://github.com/opencv/opencv/tree/master/data/haarcascades

harichandu13 avatar Jan 31 '20 12:01 harichandu13

In my case, I found that in the settings of windows 10, permission to access camera has been disabled to any applications

bakhtiyar8 avatar Feb 17 '20 13:02 bakhtiyar8

I am using hik vision's camera and i am getting same error...i think my laptop's processor is not able to load the frames due to very high resolution and frame rate

Did you find a solution?

Bilel-Marzougui avatar Feb 24 '20 08:02 Bilel-Marzougui

cv2.error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor' how to solve this

teja2002 avatar Mar 12 '20 04:03 teja2002

gray = cv2.cvtColor(image_frame, cv2.COLOR_BGR2GRAY)

error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'

mn biết lỗi này là sao k ạ

thoangnguyen1308 avatar Mar 20 '20 03:03 thoangnguyen1308

The same is happening with me

sohanatarafder99 avatar Mar 22 '20 06:03 sohanatarafder99

I realized I wasn't in the same dir as the image.I was trying to load an image from Desktop using just the image name.jpg. I changed dir into Desktop and everything worked fine.

AnabetsyR avatar Mar 25 '20 02:03 AnabetsyR

I am facing the same issue? what is causing the problem?

Shubhangipanda avatar Mar 26 '20 18:03 Shubhangipanda

I have the same problem the reason was the image name in the folder was different from the one i was calling from cv2.imread function. properly load the images. hope it helps

Ehabur avatar Apr 03 '20 14:04 Ehabur

Having the same error... Please help out!!

Capture

error - Capture2

Ashutosh002 avatar Apr 11 '20 10:04 Ashutosh002

If you use a camera: cv2.VideoCapture(0) #win cv2.VideoCapture(-1) #linux If you play local video: cv2.VideoCapture("videoFilePath")

ceaqw avatar Apr 12 '20 06:04 ceaqw

Same error

Traceback (most recent call last): File "basic/imageread.py", line 5, in img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) cv2.error: OpenCV(4.2.0) /io/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'

mohamedrashik avatar Apr 17 '20 05:04 mohamedrashik

complete image path helps me to resolve error example : cv2.imread("C:\Users\xyz\Desktop\Python\welcome.png")

shrikantkhabale avatar Apr 20 '20 16:04 shrikantkhabale

ret, frame = cv2.VideoCapture('PATH').read() You should put : ''' if ret == False break ''' above: ''' gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) cv2.imshow('gray', gray) ''' Because when it comes to the final frame of the video, then there will be no frame for ''' cv2.cvtCOLOR(frame, cv2.COLOR_BGR2GRAY) '''' _src.empty() in function 'cv::cvtColor' means that is no source for the function.

giangnguyen-bker avatar Apr 23 '20 08:04 giangnguyen-bker

cv2.error: OpenCV(4.2.0) /io/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'

Same here, the suggestions under this topic didnt work for me.

hapsuu avatar Apr 25 '20 07:04 hapsuu

gray = cv2.cvtColor(image_frame, cv2.COLOR_BGR2GRAY)

error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'

mn biết lỗi này là sao k ạ

chuyển \ thành / thử xem bạn

thangphung215 avatar Apr 25 '20 10:04 thangphung215

cv2.error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor' how to solve this

How to solve?

GreatBruceYoung avatar May 16 '20 08:05 GreatBruceYoung

error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\objdetect\src\cascadedetect.cpp:1689: error: (-215:Assertion failed) !empty() in function 'cv::CascadeClassifier::detectMultiScale'

Please help!

pratsat18 avatar May 17 '20 08:05 pratsat18

The problem is your image location. Just check carefully if you make a mistake on the location. For example if your image stored under a folder and rather in the same folder of your source code then dont use color = cv2.imread("butterfly.jpg", 1 ) instead color = cv2.imread("images/your-folder/butterfly.jpg", 1 )

hapsuu avatar May 17 '20 13:05 hapsuu

I also faced the same error and i fixed it by correcting the directory path. Earlier my code was cv2.imread("basic/imageread.png",1)

i fixed it by changing the path,make sure your path is correct. cv2.imread("../basic/imageread.png",1)

IDE: Pycharm OS: Ubuntu:18

mmohamedrashik avatar May 18 '20 04:05 mmohamedrashik

If the path is correct and the name of the image is OK, but you are still getting the error

use: from skimage import io img = io.imread(file_path)

instead of: cv2.imread(file_path)

The function imread loads an image from the specified file and returns it. If the image cannot be read (because of missing file, improper permissions, unsupported or invalid format), the function returns an empty matrix ( Mat::data==NULL ).

See this stackoverflow for more information.

okridgway avatar May 22 '20 05:05 okridgway