OpenCV imread() is not working
You need to use the waitKey()
function after imshow()
. You can pass in a delay parameter to show the image for a certain time (in milliseconds).
Example:
#--- It will display the image for 30 ms
waitKey(30);
#--- It will display the image until a key is pressed
waitKey();
Check THIS PAGE for more.
There is also a demo example shown HERE
OpenCV Python not opening images with imread()
Probably you have problem with special meaning of \
in text - like \t
or \n
Use \\
in place of \
imgloc = "F:\\Kyle\\Desktop\\Coinjar\\Test images\\ten.png"
or use prefix r''
(and it will treat it as raw
text without special codes)
imgloc = r"F:\Kyle\Desktop\Coinjar\Test images\ten.png"
EDIT:
Some modules accept even /
like in Linux path
imgloc = "F:/Kyle/Desktop/Coinjar/Test images/ten.png"
cv::imread() in OpenCV not reading my .png
It is possible that the image you are using is of corrupted data. The imread() function will not return anything to your imgTrainingNumbers matrix if you...a. have not specified the path correctly
b. the image is not in a proper format/is corrupted
c. some linking issue
Replace the image with something else to test the theory.
Why isn't imread in openCV opening some of the images?
Try changing
img = cv2.imread('C:\Users\harit\Desktop\images\12.jpg')
to
img = cv2.imread(r'C:\Users\harit\Desktop\images\12.jpg')
Backslash is an escape character, and the r before the quotes tells python to "ignore" them.
For example:
>>> s = 'C:\Users\harit\Desktop\images\12.jpg'
>>> print s
C:\Users\harit\Desktop\images
.jpg
This is the wrong path!... with an 'r' in front of the string:
>>> s = r'C:\Users\harit\Desktop\images\12.jpg'
>>> print s
C:\Users\harit\Desktop\images\12.jpg
See https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals for more on raw strings
Related Topics
How to Use Createfile, But Force the Handle into a Std::Ofstream
Difference Between Shared Objects (.So), Static Libraries (.A), and Dll's (.So)
Initialize Parent's Protected Members with Initialization List (C++)
Calling a Function for Each Variadic Template Argument and an Array
Addition of Two Chars Produces Int
How to Leverage Qt to Make a Qobject Method Thread-Safe
Creating a Transparent Window in C++ Win32
Friend and Inline Method, What's the Point
Are Memory Leaks "Undefined Behavior" Class Problem in C++
How to Declare a Global Variable in C++
How to Use Std::Async Without Waiting for the Future Limitation
Cancelling a Thread Using Pthread_Cancel:Good Practice or Bad
Order of Evaluation of Elements in List-Initialization
Why Doesn't Narrowing Conversion Used with Curly-Brace-Delimited Initializer Cause an Error