This question already has answers here:
Open CV, image loading issue on Mac OS X
(2 answers)
Closed 5 years ago.
The code:
String imageName( "test.jpg" );
Mat image = imread( imageName,IMREAD_COLOR );
if( image.empty() )
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
namedWindow( "Display window", WINDOW_AUTOSIZE );
imshow( "Display window", image );
The test.jpg file is in the same folder as the cpp file. (cpp file is in "documents/Xcode projects/ocr/ocr/")
But the program displays "Could not open or find the image" and quits. Is there something wrong with the directory of test.jpg or is it something else?
Code seems right there can be 2 problems
1. the name of the image is same as that in location(case sensitive)
2.Use the following code (i have checked it works)
int main( int argc, const char** argv )
{
Mat img = imread("yourImageNAme", CV_LOAD_IMAGE_UNCHANGED);
if (img.empty())
{
cout << "Error : Image cannot be loaded..!!" << endl;
return -1;
}
namedWindow("MyWindow", CV_WINDOW_AUTOSIZE);
imshow("MyWindow", img);
waitKey(0);
destroyWindow("MyWindow");
return 0;
}
Related
This is the piece of code. I have tried almost everything to resolve this error but the seg-fault doesn't go away. The image is getting read as the code displays the number of columns and rows in the image. I get this output upon running gdb:
SIGSEGV received from /usr/lib/x86-64-linux-gnu/libopencv_highgui.so.2.4
#include <opencv2/highgui.hpp>
#include <iostream>
int main( int argc, char** argv ) {
cv::Mat image;
image = cv::imread("sample.jpeg" , CV_LOAD_IMAGE_COLOR);
if(! image.data ) {
std::cout << "Could not open or find the image" << std::endl ;
return -1;
}
cv::namedWindow( "Display window", cv::WINDOW_AUTOSIZE );
#this line gives me errors
cv::imshow( "Display window", image );
cv::waitKey(0);
return 0;
}
I am new to openCV, have recently obtained a version of openCV 2.4.8 and was successfully able to integrate it with Code blocks.
Apparently library seems to work fine, but when I'm trying to display image using imshow it displays the window but doesn't display image in it.
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);
if(! image.data )
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
namedWindow( "Display window", WINDOW_AUTOSIZE );
imshow( "Display window", image );
waitKey(0);
return 0;
}
output of the program
Any help would be highly appreciated.
I finally got OpenCV to work but I encountered a problem where my program does not proceed (no outcome). The outcome of the program should be an image in a new window. Snippet:
#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], 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;
}
Point is, program builds successfully but when I debug it, nothing happens. I tried to Start Without Debugging (ctrl+F5, I am using MSVisual2012) and what popped up is:
How can I fix this? Is it related to bad library linking?
The output is "Usage: display_image ImageToLoadAndDisplay", which means the program didn't get the filename. You can:
image = imread("C:\myfile.jpg", IMREAD_COLOR); (and remove the previous lines)
open terminal, cd to the executable dir and run yourprogram.exe myfile.jpg
set command arguments in visual studio.
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.
This is the program i am trying but 3 errors are coming in 17th line which consist imread. i searched everywhere but i am not founding why it is showing this errors?
Errors are:
" : undeclared identifier
missing ) before string
syntax error )
#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("C:/Users/jai guru umesh/Desktop/6.jpg",0); // 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;
}