P
P
Python Newbie2021-09-08 07:54:26
OpenCV
Python Newbie, 2021-09-08 07:54:26

How to remove error in opencv python?

I have a code that should just open an image as a window:

import cv2
my_photo = cv2.imread('man.png')
cv2.imshow('preview', my_photo)
cv2.waitKey(0)
cv2.destroyAllWindows()


But at startup, the window opens and immediately closes, and the error in the console is:
Traceback (most recent call last):
  File "c:/Users/Дом/Desktop/Py/pythoncv/main.py", line 3, in <module>
    cv2.imshow('man', my_photo)
cv2.error: OpenCV(4.5.3) C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-q3d_8t8e\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'

How to solve it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aleksandr, 2021-09-08
@QQQ-RRR

Judging by this line, the man.png file should be next to the main.py file
my_photo = cv2.imread('man.png')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question