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

OpenCV Error: Failed Assertion #2

Open
teeple31 opened this issue Mar 15, 2017 · 25 comments
Open

OpenCV Error: Failed Assertion #2

teeple31 opened this issue Mar 15, 2017 · 25 comments

Comments

@teeple31
Copy link

Receiving the following error: OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /home/pi/opencv-3.1.0/modules/imgproc/src/color.cpp, line 8000
Traceback (most recent call last):
File "/home/pi/rpotter.py", line 138, in FindWand
old_gray = cv2.cvtColor(old_frame, cv2.COLOR_BGR2GRAY)
cv2.error: /home/pi/opencv-3.1.0/modules/imgproc/src/color.cpp:8000: error: (-215) scn == 3 || scn == 4 in function cvtColor

Using the Pi NoIR. Still searching for a solution.

@sean-obrien
Copy link
Owner

sean-obrien commented Mar 17, 2017 via email

@teeple31
Copy link
Author

I am running in the virtual environment.
I just tried outside of the virtual enviroment and now get a different error:

warnings.filterwarnings("ignore", category=np.VisibleDeprecationWarning)
AttributeError: 'module' object has no attribute 'VisibleDeprecationWarning'

@sean-obrien
Copy link
Owner

Can you check your numpy version both inside and outside the virtual environment?

python -c "import numpy; print numpy.__version__"

@hebertg626
Copy link

I am also having the same issue as TEEPLE31. And I am also in virtual environment when trying. I will also check my numpy versions.

@teeple31
Copy link
Author

I have 1.8.2 in both environments

@hebertg626
Copy link

1.12.0 in both.

@hebertg626
Copy link

Initializing point tracking
START switch_pin ON for pre-video test
OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /home/pi/opencv-3.1.0/modules/imgproc/src/color.cpp, line 8000
Error: /home/pi/opencv-3.1.0/modules/imgproc/src/color.cpp:8000: error: (-215) scn == 3 || scn == 4 in function cvtColor

START incendio_pin ON and set switch off if video is running
OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /home/pi/opencv-3.1.0/modules/imgproc/src/color.cpp, line 8000
No points found
Tracking Error: <type 'exceptions.NameError'>

(Raspberry Potter:1189): GLib-GObject-CRITICAL **: g_object_unref: assertion 'G_IS_OBJECT (object)' failed

(Raspberry Potter:1189): GLib-GObject-CRITICAL **: g_object_unref: assertion 'G_IS_OBJECT (object)' failed
Tracking Error: <type 'exceptions.NameError'>

@sean-obrien
Copy link
Owner

Ok - I'm rebuilding so I can dig into this... right now I'm thinking this is related to the virtual environment and the OpenCV python bindings...

@hebertg626
Copy link

hebertg626 commented Mar 18, 2017 via email

@teeple31
Copy link
Author

Everything I am reading is that OpenCV and PiCamera do not play well together.

@sean-obrien
Copy link
Owner

sean-obrien commented Mar 20, 2017 via email

@teeple31
Copy link
Author

teeple31 commented Mar 20, 2017

3.1

--- Just remembered to check my python instance outside of the virtual env.

Outside of virtual env:
$ python 3.4

import cv2
ImportError: No module named 'cv2'


$ python

import cv2
cv2.version
3.1

Inside virtual env:
$ python #python3.4

@hebertg626
Copy link

Import error no module named cv2.

@teeple31
Copy link
Author

Problem solved for me. Need to make sure I am running python2.7 in virtual env.

@hebertg626
Copy link

hebertg626 commented Mar 21, 2017 via email

@hebertg626
Copy link

pi@raspberrypi:~ $ python
Python 2.7.9 (default, Sep 17 2016, 20:26:04)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import cv2
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named cv2

[1]+ Stopped python
pi@raspberrypi:~ $ source /.profile
pi@raspberrypi:
$ workon cv
(cv) pi@raspberrypi:~ $ python
Python 2.7.9 (default, Sep 17 2016, 20:26:04)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.

@teeple31
Copy link
Author

Try:
$ sudo modprobe bcm2835-v4l2

@teeple31
Copy link
Author

Meant to say:

$ source ~/.profile
$ workon cv
---assuming you are now in virtual env---
$ sudo pigpiod
$ sudo modprobe bcm2835-v4l2
$ python2.7 rpotter.py

@hebertg626
Copy link

hebertg626 commented Mar 21, 2017 via email

@shaynakapadia
Copy link

I am also getting a similar error.
Initializing point tracking
OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /home/pi/opencv-3.2.0/modules/imgproc/src/color.cpp, line 9748
Error: /home/pi/opencv-3.2.0/modules/imgproc/src/color.cpp:9748: error: (-215) scn == 3 || scn == 4 in function cvtColor

OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /home/pi/opencv-3.2.0/modules/imgproc/src/color.cpp, line 9748
Traceback (most recent call last):
File "rpotter.py", line 204, in
TrackWand()
File "rpotter.py", line 133, in TrackWand
old_gray = cv2.cvtColor(old_frame, cv2.COLOR_BGR2GRAY)
cv2.error: /home/pi/opencv-3.2.0/modules/imgproc/src/color.cpp:9748: error: (-215) scn == 3 || scn == 4 in function cvtColor

sudo modprobe bcm2835-v4l2 fixed the first error, but I am not sure what to do about the 2nd error.

Anyone have any other ideas on how to fix it?

@teeple31
Copy link
Author

teeple31 commented Apr 22, 2017 via email

@shaynakapadia
Copy link

Python 2.7
Is it a problem with the version?

@bkirchman
Copy link

Anyone figure out this issue, same as sallyliest over here

@shaynakapadia
Copy link

A friend of mine figured it out and we got it to work.
I just had to comment out line 250: cam.release()
I also did what teeple3 said to do.

Also make sure you use the code that's in the ollivanderslamp folder.

I ran into a couple other issues with linking the python modules so if you had a problem with that just lmk.

@jcfitzg
Copy link

jcfitzg commented Dec 20, 2017

I've been working on this damn lamp for so long, and have finally gotten far enough to even understand how to follow your instructions. I have just gotten picture and tracking marks up on the pi via ssh and and pretty proud of myself, but of course I could have done none of it without you sharing your knowledge and experience. Thanks to you, my daughter will have her harry potter lamp under the tree this xmas.

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

No branches or pull requests

6 participants