Ask Your Question
0

How to solve this cvtColor() error? "cv2.error: C:\builds\master_PackSlaveAddon-win32-vc12-static\opencv\modules\imgproc\src\color.cpp:7456: error: (-215) scn == 3 || scn == 4 in function cv::ipp_cvtColor"

asked 2016-06-08 01:10:27 -0600

omee gravatar image

updated 2016-06-08 01:14:58 -0600

I am trying to run the following code:

import numpy as np
import cv2

cap = cv2.VideoCapture(0)

while(True):
    # capture frame-by-frame
    ret, frame = cap.read()

    # our operation on 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 is done release the capture
cap.release()
cv2.destroyAllWindows()

But I get this error when I run it:

    Traceback (most recent call last):
      C:\Python27\python.exe C:/OpenCV_Python/Python_Test.py
OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cv::ipp_cvtColor, file C:\builds\master_PackSlaveAddon-win32-vc12-static\opencv\modules\imgproc\src\color.cpp, line 7456
Traceback (most recent call last):
  File "C:/OpenCV_Python/Python_Test.py", line 11, in <module>
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.error: C:\builds\master_PackSlaveAddon-win32-vc12-static\opencv\modules\imgproc\src\color.cpp:7456: error: (-215) scn == 3 || scn == 4 in function cv::ipp_cvtColor

Please help. Thanks a lot in advance.

edit retag flag offensive close merge delete

Comments

Isnt it the wrong number of channels? It is looking for 3 and there are 4? Inquiring minds want to know. :o)

jmbapps gravatar imagejmbapps ( 2016-06-08 08:57:53 -0600 )edit

Thanks a lot sir

Badal gravatar imageBadal ( 2017-10-22 12:16:43 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
1

answered 2016-06-08 03:33:36 -0600

berak gravatar image

basically, the frame you're trying to process is empty / invalid.

add some sanity checks, like:

import numpy as np
import cv2

cap = cv2.VideoCapture(0)

while(cap.isOpened()):  # check !
    # capture frame-by-frame
    ret, frame = cap.read()

    if ret: # check ! (some webcam's need a "warmup")
        # our operation on 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 is done release the capture
cap.release()
cv2.destroyAllWindows()
edit flag offensive delete link more

Comments

Okay! Thanks a lot! It helped.

omee gravatar imageomee ( 2016-06-09 10:49:19 -0600 )edit

hello sir..i tried this exact code.....it runs without errors but nothing gets displayed..pls help

shubham_53 gravatar imageshubham_53 ( 2017-11-17 00:37:16 -0600 )edit

it takes time, but worked, Thank you very much

JJohnJ gravatar imageJJohnJ ( 2018-06-19 10:49:26 -0600 )edit

I'm trying exactly this code. it has no error but nothing is displayed.why is this happening?please help me

nastaran98 gravatar imagenastaran98 ( 2019-09-07 10:49:15 -0600 )edit
0

answered 2018-07-30 05:23:49 -0600

i am trying to run below code:

edit flag offensive delete link more

Comments

import math

import cv2 import numpy as np import random from collections import deque

cap = cv2.VideoCapture(1)

To keep track of all point where object visited

center_points = deque()

while True: # Read and flip frame ret, frame = cap.read() frame = cv2.flip(frame, 1)

# Blur the frame a little
blur_frame = cv2.GaussianBlur(frame, (7, 7), 0)

# Convert from BGR to HSV color format
hsv = cv2.cvtColor(blur_frame, cv2.COLOR_BGR2HSV)

# Define lower and upper range of hsv color to detect. Blue here
lower_blue = np.array([100, 50, 50])
upper_blue = np.array([140, 255, 255])
mask = cv2.inRange(hsv, lower_blue, upper_blue)

# Make elliptical kernel
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (15, 15))

# Opening morph(erosion
maraboina vamshi gravatar imagemaraboina vamshi ( 2018-07-30 05:24:25 -0600 )edit

its showing error as:

maraboina vamshi gravatar imagemaraboina vamshi ( 2018-07-30 05:25:31 -0600 )edit

Traceback (most recent call last): File "C:\Users\HP\Desktop\Python programms\py projects\object_tracking.py", line 21, in <module> hsv = cv2.cvtColor(blur_frame, cv2.COLOR_BGR2HSV) error: ........\opencv\modules\imgproc\src\color.cpp:3961: error: (-215) (scn == 3 || scn == 4) && (depth == CV_8U || depth == CV_32F) in function cv::cvtColor

maraboina vamshi gravatar imagemaraboina vamshi ( 2018-07-30 05:25:50 -0600 )edit

@maraboina vamshi please stop with your Jigsaw puzzle and ask a new question with all your comment in your newquestion

LBerger gravatar imageLBerger ( 2018-07-30 05:31:37 -0600 )edit

@maraboina vamshi , i'll delete this, it is not an answer.

if you have a question, please assk one insterd !

berak gravatar imageberak ( 2018-07-30 06:29:20 -0600 )edit
0

answered 2017-12-04 05:38:12 -0600

supra56 gravatar image

@shubham_53. There are nothing wrong with both @berak and @omee. I tested them both are working.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-06-08 01:10:27 -0600

Seen: 84,345 times

Last updated: Dec 04 '17