You are not logged in.

#1 2017-11-08 06:23:22

hellraise007
Member
Registered: 2017-11-08
Posts: 5

OpenCV error : Assertion Failed

I was testing my opencv installation by running the first code in https://docs.opencv.org/3.3.1/dd/d43/tu … splay.html

mpf.py

 import numpy as np
import cv2
cap = cv2.VideoCapture(0)
while(True):
    # Capture frame-by-frame
    ret, frame = cap.read()
    # Our operations on the frame come here
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    # Display the resulting frame
    cv2.imshow('frame',gray)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows() 

On running

 python mfp.py 

I get this error

 OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /io/opencv/modules/imgproc/src/color.cpp, line 10638
Traceback (most recent call last):
  File "mfp.py", line 8, in <module>
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.error: /io/opencv/modules/imgproc/src/color.cpp:10638: error: (-215) scn == 3 || scn == 4 in function cvtColor

OpenCV Version = 3.3.1

I am a complete newbie to openCV and python .

Note to Moderators : It is my first thread in arch forum . If i posted in the wrong section please move this to the right section.

Last edited by hellraise007 (2017-11-08 06:27:40)

Offline

#2 2017-11-08 15:07:58

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,739

Re: OpenCV error : Assertion Failed

This section is fine.    I installed opencv, opened a python shell and entered lines 2,3,6,and 8 from your script and it worked fine here.  Well, no assertion anyway.

I note that there were many optional dependencies for opencv.  I already had them all installed with the exception of vcdimager, which I did not install.
Please verify how you installed opencv.  Also, what optional dependencies you have.

I know nothing of opencv (but it looks interesting).  I don't imagine it care what GPU you have, but mine is Intel.  As to video sources, I have a USB webcam built into my HP Envy Laptop.  What are your video sources?


Edit:  Oh, Welcome to the Arch Linux forums smile

Last edited by ewaller (2017-11-08 15:08:38)


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#3 2017-11-10 08:42:57

hellraise007
Member
Registered: 2017-11-08
Posts: 5

Re: OpenCV error : Assertion Failed

ewaller wrote:

This section is fine.    I installed opencv, opened a python shell and entered lines 2,3,6,and 8 from your script and it worked fine here.  Well, no assertion anyway.

I note that there were many optional dependencies for opencv.  I already had them all installed with the exception of vcdimager, which I did not install.
Please verify how you installed opencv.  Also, what optional dependencies you have.

I know nothing of opencv (but it looks interesting).  I don't imagine it care what GPU you have, but mine is Intel.  As to video sources, I have a USB webcam built into my HP Envy Laptop.  What are your video sources?


Edit:  Oh, Welcome to the Arch Linux forums smile

Thank you for the warm welcome
As for installing python , i reinstalled it with all the optional dependencies .

$ glxinfo|egrep "OpenGL vendor|OpenGL renderer"
OpenGL vendor string: Intel Open Source Technology Center
OpenGL renderer string: Mesa DRI Intel(R) Haswell Mobile 

When runnning the code from shell , as i reach line 8 i get this error:

>>  gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
 OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /io/opencv/modules/imgproc/src/color.cpp, line 10638
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
cv2.error: /io/opencv/modules/imgproc/src/color.cpp:10638: error: (-215) scn == 3 || scn == 4 in function cvtColor

Am i doing anything wrong?

Offline

#4 2017-11-10 16:29:56

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,739

Re: OpenCV error : Assertion Failed

When I had been helping you before I was ssh'ing into my box from work, thus I could not actually run your program.
I am at home today and was able to try your program.   When I run it, I get a grey-scale picture of an ugly Arch Linux Moderator.  tongue

ewaller@turing ~ 1001 %glxinfo|egrep "OpenGL vendor|OpenGL renderer"
OpenGL vendor string: Intel Open Source Technology Center
OpenGL renderer string: Mesa DRI Intel(R) Haswell Mobile 
ewaller@turing ~ 1002 %

Curious.   What are the output of :
pacman -Q opencv
uname -a
pacman -Q linux

Are you running this from a console, Xorg or Wayland?  I am running inside Xorg under i3wm


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#5 2017-11-10 17:14:47

hellraise007
Member
Registered: 2017-11-08
Posts: 5

Re: OpenCV error : Assertion Failed

ewaller wrote:

When I had been helping you before I was ssh'ing into my box from work, thus I could not actually run your program.
I am at home today and was able to try your program.   When I run it, I get a grey-scale picture of an ugly Arch Linux Moderator.  tongue

ewaller@turing ~ 1001 %glxinfo|egrep "OpenGL vendor|OpenGL renderer"
OpenGL vendor string: Intel Open Source Technology Center
OpenGL renderer string: Mesa DRI Intel(R) Haswell Mobile 
ewaller@turing ~ 1002 %

Curious.   What are the output of :
pacman -Q opencv
uname -a
pacman -Q linux

Are you running this from a console, Xorg or Wayland?  I am running inside Xorg under i3wm

➜  ~ pacman -Q opencv
opencv 3.3.1-2
➜  ~ uname -a        
Linux Matrix 4.13.11-1-ARCH #1 SMP PREEMPT Thu Nov 2 10:25:56 CET 2017 x86_64 GNU/Linux
➜  ~ pacman -Q linux
linux 4.13.11-1

Running in deepin-terminal in deepin desktop manager

➜  ~ loginctl show-session c2 -p Type 
Type=x11

Running form tty2 also result in same errors

Last edited by hellraise007 (2017-11-10 17:38:11)

Offline

#6 2017-11-14 07:23:36

hellraise007
Member
Registered: 2017-11-08
Posts: 5

Re: OpenCV error : Assertion Failed

Problem solved after I installed everything clean from source . Does this mean arch repositories are hosting out dated packages?

Offline

#7 2017-11-14 15:24:02

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,739

Re: OpenCV error : Assertion Failed

Don't think so.  One thing we had not explored; was your system fully up to date (pacman -Syu) ?


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

Board footer

Powered by FluxBB