#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <iostream>
using namespace cv;
int main()
{
Mat image;
image = imread("Test.jpg", IMREAD_COLOR);
if(image.empty())
{
std::cout << "Could not open or find the image" << std::endl;
return -1;
}
namedWindow("Display window", WINDOW_AUTOSIZE)
imshow("Display window", image);
waitKey(0);
}
I wrote this bit of code, but somehow it can't find the image.If I create a new image inside the "Resource Files" folder it works perfectly fine. Both images are inside the folder.
I'm using Visual Studio 2017
Related
I'm trying to get OpenCV to work with visual studio. After following the official OpenCV installation instructions down to the letter, I tried building a sample program. I got the error in the title. The odd part is that the namespace 'cv' works fine - there are no errors for the rest of the code. Here's the sample program I tried to build:
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
if (argc != 2)
{
cout << " Usage: display_image ImageToLoadAndDisplay" << endl;
return -1;
}
Mat image;
image = imread(argv[1], IMREAD_COLOR); // Read the file
if (image.empty()) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl;
return -1;
}
namedWindow("Display window", 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;
}
In addition, here's my list of additional dependencies that I put in the project properties:
opencv_calib3d320d.lib
opencv_core320d.lib
opencv_features2d320d.lib
opencv_flann320d.lib
opencv_highgui320d.lib
opencv_imgcodecs320d.lib
opencv_imgproc320d.lib
opencv_ml320d.lib
opencv_objdetect320d.lib
opencv_photo320d.lib
opencv_shape320d.lib
opencv_stitching320d.lib
opencv_superres320d.lib
opencv_ts320d.lib
opencv_video320d.lib
opencv_videoio320d.lib
opencv_videostab320d.lib
I badly need this work :( . It should be noted that I have quadruple-checked the instructions to make this work, so I don't think it has to do with the header files or something.
I had some Problems to run the following simple code:
http://docs.opencv.org/doc/tutorials/introduction/display_image/display_image.html
System: Windows 7 x64
Microsoft Visual Studio 2013 (free to use)
Project for 32 bit.
I had many various linking error as LNK2001 and LNK2019.
all of it was solved when I added this Libraries under "Configuration Prosperities"> "Linker" > "Input"
Libraries under "Configuration Prosperities"> "Linker" > "Input":
opencv_calib3d300.lib
opencv_core300.lib
opencv_features2d300.lib
opencv_flann300.lib
opencv_hal300.lib
libtiff.lib
libpng.lib
libjpeg.lib
libjasper.lib
IlmImf.lib
zlib.lib
opencv_highgui300.lib
opencv_imgproc300.lib
opencv_imgcodecs300.lib
opencv_ml300.lib
opencv_objdetect300.lib
opencv_photo300.lib
opencv_shape300.lib
opencv_stitching300.lib
opencv_ts300.lib
opencv_video300.lib
opencv_videostab300.lib
ippicvmt.lib
libwebp.lib
I used this code:
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
#include <iostream>
#include <stdlib.h>
#include "stdafx.h"
#include <opencv2/opencv.hpp>
#include <opencv2/shape.hpp>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
if (argc != 2)
{
cout << " Usage: display_image ImageToLoadAndDisplay" << endl;
return -1;
}
Mat image;
image = imread(argv[1], IMREAD_COLOR); // Read the file
if (!image.data) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl;
return -1;
}
namedWindow("Display window", 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;
}
I have an image of dimension 4096 X 2304. I can view that Image when double click.
Then i wanted to write my own opencv (ver 2.4.3) program to display this image. But The image is not fitting on the screen. It is showing only 50%, rest of the part is cutting.
This my code for image display:
#include "stdafx.h"
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
Mat im = imread("1.jpg");
if (im.empty())
{
cout << "Cannot load image!" << endl;
return -1;
}
imshow("Image", im);
waitKey(0);
}
The screen resolution of my monitor is 1366 x 768 maximum.
So why my program is unable to display the full uncut image?
Try this (I have done partial editing of your code, just the gutsy bits 0_0 ):
Mat im_s = imread("myimg", CV_LOAD_IMAGE_COLOR);
if (im_s.empty())
{
cout << "Cannot load image!" << endl;
return -1;
}
namedWindow( "Myimg", WINDOW_AUTOSIZE );
Size size(4096,2304);
Mat im;
resize(im_s, im, size);
imshow("Myimg", im);
waitkey(0);
return 0;
I am using OpenCV 2.4.9 in Visual Studio 2010 and am trying to run simple source code provided on a tutorial website:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
if( argc != 2)
{
cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
return -1;
}
Mat image;
image = imread(argv[1], CV_LOAD_IMAGE_COLOR); // Read the file
if(! image.data ) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
cout << argv[1] << std::endl;
return -1;
}
namedWindow( "Display window", 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;
}
However, when I try to run the executable (and comment out that if statement) I get: Assertion failed (size.width>0 && size.height>0) in cv::imshow ......(file path)
I have looked at just about every related thread I have found on here. The file path is not wrong, I have printed it out and even moved the executable and jpg to the same folder.
Furthermore, this sample code from another tutorial does the exact same thing flawlessly, so I doubt it's a project configuration error but not sure:
#include <opencv2/opencv.hpp>
using namespace cv;
int main()
{
IplImage *img = cvLoadImage("C:\\Users\\bomoon\\Documents\\Koala.jpg", 1);
cvNamedWindow("test");
cvShowImage("test", img);
cvWaitKey(0);
cvReleaseImage(&img);
cvDestroyWindow("test");
return 0;
}
Can anyone explain why the second program works but not the first, and how I can fix the first one?
P.S.: It's not that I need to find a workaround to accomplish something, I'm trying to run sample code to verify the installation works, but it apparently doesn't if one sample program runs but not the other.
I want to compile the following code, which seems to be valid:
#include "stdafx.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
if( argc != 2)
{
cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
return -1;
}
Mat image;
image = imread(argv[1], CV_LOAD_IMAGE_COLOR); // Read the file
if(! image.data ) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
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;
}
After that, every .dll was found, except this one: "C:\Windows\System32\nvinitx.dll". How i am able to solve this? I found out, that this .dll is the driver of my NVIDIA GeForce GTX 660M.