c++ cvShowImage error

3.4k views Asked by At

I want to load an image with opencv. Everything is working properly but it doesn't show me the image. Code what I usin is here: #include #include #include

 using namespace cv;
 using namespace std;

 int main( int argc, const char** argv )
 {
     IplImage *img = cvLoadImage("D:/C++/ MGC.JPG");

     cvNamedWindow("MyWindow", 1); //create a window with the name "MyWindow"
     cvMoveWindow("MyWindow", 100, 100);
     cvShowImage("MyWindow", img);

     cvWaitKey(0); //wait infinite time for a keypress
     cvDestroyWindow("MyWindow"); //destroy the window with the name, "MyWindow"

     return 0;
 }
1

There are 1 answers

4
go4sri On

Is there a specific reason you chose to use the C interface? If not, you should be using the C++ interface

int main( int argc, const char** argv )
{
    cv::Mat image = cv::imread("D:/C++/ MGC.JPG");
    cv::namedWindow("MyWindow", 256);
    cv::imshow("MyWindow", image );
    cv::waitKey();
    return 0;
}