If you call a function from another file, you will not be able to open the image.If you don't call, you can run it safely.
No OpenCV is used for calling functions.
from pathlib import Path
import cv2
I can't open the image when I call the following function.
# from classfy02 import input_data
defmain():
parent_path=Path(__file__).parent
path = str(
(parent_path/'cross.png') .resolve()
)
img=cv2.imread(path)
cv2.namedWindow('screen', cv2.WINDOW_NORMAL)
cv2.setWindowProperty('screen', cv2.WND_PROP_FULLSCREEN,
cv2.WINDOW_FULLSCREEN)
cv2.imshow('screen',img)
cv2.waitKey(1000)
if__name__=='__main__':
main()
The error is as follows:
OpenCV Error: Assertion failed (size.width>0&size.height>0) inimshow, file/Users/travis/build/skvark/opencv -
python/opencv/modules/highgui/src/window.cpp, line 325
Traceback (most recent call last):
File "path.py", line 15, in <module>
cv2.imshow('screen',img)
cv2.error: /Users/travis/build/skvark/opencv-
python/opencv/modules/highgui/src/window.cpp:325:error:(-215)size.width>0&size.height>0 in function imshow
What do you think is the cause?
Thank you for your cooperation.
"The question says, ""If you call the following functions, the image will not open."""
#from classfy02 import input_data
is the import of the module, not the invocation of the function.
Therefore, what is happening is probably the problem of "importing input_data from the classfy02 module" and preventing the image from being opened.
=
The error OpenCV Error: Assertion failed (size.width>0&size.height>0) indicates that the Assertion was not met because the image used when some function of OpenCV was performed was abnormal (width or height is 0 or negative).
=
The following scenarios are inferred from these scenarios:
·The cv2 module contains a function called input_data
·The input_data of the cv2 module is used to read image data
·"From classfy02 import input_data" now means input_data of classfy02 module instead of input_data of cv2 module
·Cv2 module used input_data of classfy02 module when loading image data, so loading image data failed
·As the image data read failed (the acquired image is empty), Assertion was not satisfied
=
Whether the above scenarios are correct or not,
"from classfy02 import input_data"
instead of
"from classfy02 import input_data as input_data_classfy02"
You will find out by doing .
If you import the input_data of classfy2 under another name (input_data_classfy02) such as "from classfy02 import input_data as input_data_classfy02", the input_data of cv2 will be used in input_data, and there should be no problem if the image data cannot be read.
Try it.
© 2024 OneMinuteCode. All rights reserved.