Skip to content

error: (-215:Assertion failed) !_src.empty() in function 'cvtColor' #276

@kpythonvision

Description

@kpythonvision

Expected behaviour:

Following an OpenCV tutorial. Followed instructions on https://pypi.org/project/opencv-contrib-python/. The package works great until the tutorial asks to include the following in the script

gray = cv2.cvtColor(color, cv2.COLOR_RGB2GRAY)

Write here how did you expect the library to function.
The tutorial asks to create a script to transform different layers
Following the video it is supposed to split the channels and convert them to grayscale. I'm not 100% sure since I'm new.

Actual behaviour

The following error occurs when running the command:

python3 02_05.py

with pwd in the required folder

File "02_05.py", line 6, in <module> gray = cv2.cvtColor(color, cv2.COLOR_RGB2GRAY) cv2.error: OpenCV(4.1.2) /Users/travis/build/skvark/opencv-python/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'

Steps to reproduce

  • example code:: This is the full script::
    `import numpy as np
    import cv2

color = cv2.imread("butterfly,jpg",1 )

gray = cv2.cvtColor(color, cv2.COLOR_RGB2GRAY)
cv2.imwrite("gray.jpg", gray)

b = color [:,:, 0]
g = color [:,:, 1]
r = color [:,:, 2]

rgba = cv2.merge((b,g,r, g))
cv2.imwrite("rgba.png", rgba)
` That was the full script

  • operating system : Mac OSX Mojave 10.14.4
  • architecture (e.g. x86) : Mac OSX Mojave 10.14.4 (Apple?)
  • opencv-python version : opencv-contrib-python 4.1.2.30

Thank you. I'm new to GIT and I'm new to OpenCV. And Happy New year!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions