Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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' #933

Open
rezabrg opened this issue Sep 17, 2019 · 28 comments

Comments

@rezabrg
Copy link

@rezabrg rezabrg commented Sep 17, 2019

  • 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.
@rafaelpsimoes
Copy link

@rafaelpsimoes rafaelpsimoes commented Oct 24, 2019

i have the same problem

@ageitgey
Copy link
Owner

@ageitgey ageitgey commented Oct 24, 2019

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.

@tarvihafatima
Copy link

@tarvihafatima tarvihafatima commented Nov 12, 2019

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".

@yashpatel7025
Copy link

@yashpatel7025 yashpatel7025 commented Dec 12, 2019

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

@dinezh256
Copy link

@dinezh256 dinezh256 commented Dec 20, 2019

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

@ghost
Copy link

@ghost ghost commented Dec 25, 2019

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)

@vijaypearl
Copy link

@vijaypearl vijaypearl commented Jan 24, 2020

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'

@nikhilsupertramp
Copy link

@nikhilsupertramp nikhilsupertramp commented Jan 26, 2020

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
Copy link

@nikhilsupertramp nikhilsupertramp commented Jan 26, 2020

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

@harichandu13
Copy link

@harichandu13 harichandu13 commented Jan 31, 2020

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

@bakhtiyar8
Copy link

@bakhtiyar8 bakhtiyar8 commented Feb 17, 2020

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

@Bilel-Marzougui
Copy link

@Bilel-Marzougui Bilel-Marzougui commented Feb 24, 2020

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?

@teja2002
Copy link

@teja2002 teja2002 commented Mar 12, 2020

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

@thoangnguyen1308
Copy link

@thoangnguyen1308 thoangnguyen1308 commented Mar 20, 2020

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 ạ

@sohanatarafder99
Copy link

@sohanatarafder99 sohanatarafder99 commented Mar 22, 2020

The same is happening with me

@AnabetsyR
Copy link

@AnabetsyR AnabetsyR commented Mar 25, 2020

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.

@Shubhangipanda
Copy link

@Shubhangipanda Shubhangipanda commented Mar 26, 2020

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

@Ehabur
Copy link

@Ehabur Ehabur commented Apr 3, 2020

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

@Ashutosh002
Copy link

@Ashutosh002 Ashutosh002 commented Apr 11, 2020

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

Capture

error -
Capture2

@ceaqw
Copy link

@ceaqw ceaqw commented Apr 12, 2020

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

@Droid-Code
Copy link

@Droid-Code Droid-Code commented Apr 17, 2020

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'

@shrikantkhabale
Copy link

@shrikantkhabale shrikantkhabale commented Apr 20, 2020

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

@giang-nguyentbk
Copy link

@giang-nguyentbk giang-nguyentbk commented Apr 23, 2020

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.

@hapsuu
Copy link

@hapsuu hapsuu commented Apr 25, 2020

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.

@thangphung215
Copy link

@thangphung215 thangphung215 commented Apr 25, 2020

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

@Java-Young
Copy link

@Java-Young Java-Young commented May 16, 2020

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?

@pratsat18
Copy link

@pratsat18 pratsat18 commented May 17, 2020

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!

@hapsuu
Copy link

@hapsuu hapsuu commented May 17, 2020

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 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
You can’t perform that action at this time.