OpenCV imread() is not working - opencv

I have this simple code to open an image but it shows blank image in the "Video" window. I have checked release and debug lib's to make sure. It is in release mode and the lib is release lib. The picture is there, and I also tried full path for the image but still doesn't work. Also tried different image formats: jpg, png, bmp. It is OpenCV 3.4.1 release, and VS 2017 (also tried 2015).
#include "stdafx.h"
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main()
{
namedWindow("Video");
Mat frame1 = imread("Penguins.bmp", CV_LOAD_IMAGE_COLOR );
imshow("Video", frame1);
system("Pause");
return 0;
}
Thanks in advance

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

Related

opencv imread not working but other functions are

#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <string>
#include <iostream>
#include <stdlib.h>
#include "opencv2\highgui.hpp"
#include "opencv2\imgproc.hpp"
#include "opencv2\features2d.hpp"
#include "opencv2\core.hpp"
using namespace std;
using namespace cv;
int main()
{
Mat img = Mat::zeros(Size(60,60),CV_8UC1);
imwrite("test.bmp", img);
Mat img2 = imread("Screw.png");
namedWindow("image", WINDOW_NORMAL);
imshow("image", img);
imshow("img", img2);
waitKey(0);
return 0;
}
I am using Opencv 3.4.6 with visual studio 2015.
I am unable to read any image from system, have tried png and jpg image format.To make sure that image is in the right location I have also used imwrite function to save an blank image, which is working fine.
I have tried opencv 4.0.1 as well giving the same issue.
I think there might be some issue in configuration part. There are so many tutorials available for the configuration procedure. Try below link for the configuration and also
as #mark suggested replace your header file
https://www.youtube.com/watch?v=M-VHaLHC4XI

imshow in OpenCv shows black screen

I have created a project once and it was working properly, after reinstalling operation system, I set up the enviroment and all the components and suddenly i am not getting any output at all. My program for testing is simple:
#include <cstdio>
#include "opencv2/opencv.hpp"
#include <iostream>
#include <sstream>
using namespace cv;
using namespace std;
int main(int, char**)
{
VideoCapture cap("videofile.avi");
if (!cap.isOpened()) // check if we succeeded
return -1;
namedWindow("Frame", 1);
for (;;)
{
Mat frame;
if (!cap.read(frame)) {
cerr << "Unable to read next frame." << endl;
cerr << "Exiting..." << endl;
exit(EXIT_FAILURE);
}
imshow("Frame", frame);
if (waitKey(30) >= 0) break;
}
return 0;
}
I have installed all necessary codecs and updated video card drivers. Still getting the same black screen.
The output looks like this:
EDIT:
The problem appears to be only when playing .avi videos with AVC codec
EDIT:
At the end the bin folder was missing in PATH variable, so after adding new entry - %OPENCV_DIR%\bin, everything is working propelly.
Clumsy solution:
get opencv_ffmpeg300.dll, opencv_ffmpeg.dll, those can be found right in opencv library
- get openh264-1.5.0-win64msvc.dll this one can be found at Openh264
- copy all those into the working directory of the project

CodeBlocks IDE Open CV MingW Windows 7

I have installed Codeblocks with MingW, followed the instructions given HERE
I downloaded CodeBlocks with MingW. Followed the instructions in the above link, and wrote the following program
Code:
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
int main()
{
cout<<"Testing";
Mat image;// new blank image
image = cv::imread("test.png", 0);// read the file
namedWindow( "Display window", CV_WINDOW_AUTOSIZE );// create a window for display.
imshow( "Display window", image );// show our image inside it.
waitKey(0);// wait for a keystroke in the window
return 0;
}
Default compiler options set to GCC Compiler.
When I clicked Build and Run button on the IDE, it showed an "Entry Point Not Found" error message that says "The Procedure entry point__gxx_personality_v0 could not be located in the dynamic link library libstdc++-6.dll"
I dont understand what is happening. I have been trying to run this small code with various IDEs. I could not understand what went wrong.
I am the creator of the tutorial you followed! I've updated it to fix this issue - Namely the best way to use OpenCV with MinGW on Windows currently is to build your own binaries using cmake.
Best,
Kevin

displaying an image in mat form

I am trying to read an image in mat form in opencv and display it.
the code compiles fine but when run gives runtime error and the image is not displayed.
here is my code:
#include "stdafx.h"
#include<cv.h>
#include<highgui.h>
#include<iostream>
using namespace cv;
using namespace std;
void main()
{
Mat Img;
Img=imread("C:/Documents and Settings/image1.jpg");
cvNamedWindow("Image",CV_WINDOW_AUTOSIZE);
imshow( "Image", Img );
cvWaitKey(0);
}
Could anyone please tell me where am I going wrong?
Most probably imread() is failing. You will know for certain unless you start checking the success of the functions, such an important thing to do when you code.
There's a couple of reasons why it might fail:
You don't have permission to access the file.
The path is wrong.
In your case, it's probably the first. So change your code to:
Mat Img;
Img = imread("C:\\Documents and Settings\\image1.jpg");
if (Img.empty()) {
std::cout << "!!! Failed to open the file\n";
return;
}
and notice how the path to file is different.

Error with OpenCV code - Invalid address specified to RtlFreeHeap

I have the following code, which runs fine:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/features2d/features2d.hpp>
using namespace std;
using namespace cv;
void main() {
bool running = true;
cv::OrbFeatureDetector OrbDetector;
while (running) {
IplImage *newFrame = cvLoadImage("x1.jpg");
IplImage *newFrameBW = cvCreateImage(cvGetSize(newFrame), newFrame->depth, 1);
cvConvertImage(newFrame, newFrameBW);
vector<KeyPoint> KeyPoints;
}
}
However, adding the line:
OrbDetector.detect(newFrameBW, KeyPoints);
to the while loop results in the following error:
HEAP[Example 4.exe]: Invalid address specified to RtlFreeHeap( 006B0000, 02474D20 )
Example 4.exe has triggered a breakpoint.
I am sure there is nothing wrong with the code, as I have just seen it run successfully on someone elses machine. Is there anything non code related that could be causing this?
The problem is that the OpenCV version you are using does not deal OK with MCVS 2012. Is not a problem of code, as I had a similar one that include vectors and didn't work.
Take a look to this tutorial that will show you how to rebuild the OpenCV library and your code will work pretty well ;)
Here is the link:
http://answers.opencv.org/question/6495/visual-studio-2012-and-rtlfreeheap-error/

Resources