R
R
Redrik052021-03-09 13:47:01
Python
Redrik05, 2021-03-09 13:47:01

Why doesn't the code with opencv-python work?

Good afternoon! I decided to learn OpenCV, but the very first example from the Internet did not want to work on my computer. How to solve the problem?

import cv2


def load_image():
    img = cv2.imread('qrcode.jpg', cv2.IMREAD_GRAYSCALE)
    cv2.imshow('me', img)
    cv2.waitKey(0)
    cv2.imwrite('grayMe.jpg', img)


load_image()


Windows 10, Paycharm, Python 3.9

Error:
Traceback (most recent call last):
  File "C:\Users\Багаудин\PycharmProjects\pythonProject5\main.py", line 11, in <module>
    load_image()
  File "C:\Users\Багаудин\PycharmProjects\pythonProject5\main.py", line 6, in load_image
    cv2.imshow('me', img)
cv2.error: OpenCV(4.5.1) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-wvn_it83\opencv\modules\highgui\src\window.cpp:376: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'


Pycharm highlights all methods with the comment: Cannot find reference 'imread' in '__init__.py | __init__.py'

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question