Ask Your Question

hotmail's profile - activity

2014-09-14 04:39:17 -0500 commented question How to entre the name of image?

I modified the above codes that it doesn’t need to run in cmdline. Just you need to change the value of array from 100 to higher value if the address of image is more than 100 characters. Amir

2014-09-12 18:28:08 -0500 commented question How to entre the name of image?

See! I understand what your mean, but is there another way to load and display image for example using dialog box? Amir

2014-09-12 01:55:22 -0500 asked a question How to entre the name of image?

I have run the following codes that were given in the tutorial of "load and display an image" but the program was running very fast and closed before let me to write the name of the image. How can fix this problem? Also, there is any tutorial for load and display an image using dialog box?

Regards

Amir

#include <opencv2/core/core.hpp> 
2 #include <opencv2/imgcodecs.hpp> 
3 #include <opencv2/highgui/highgui.hpp> 
4 #include <iostream> 
5 

6 using namespace cv; 
7 using namespace std; 
8 

9 int main( int argc, char** argv ) 
10 { 
11     if( argc != 2) 
12     { 
13      cout <<" Usage: display_image ImageToLoadAndDisplay" << endl; 
14      return -1; 
15     } 
16 

17     Mat image; 
18     image = imread(argv[1], IMREAD_COLOR); // Read the file 
19 

20     if( image.empty() )                      // Check for invalid input 
21     { 
22         cout <<  "Could not open or find the image" << std::endl ; 
23         return -1; 
24     } 
25 

26     namedWindow( "Display window", WINDOW_AUTOSIZE ); // Create a window for display. 
27     imshow( "Display window", image );                // Show our image inside it. 
28 

29     waitKey(0); // Wait for a keystroke in the window 
30     return 0; 
31 }

My own solution for not adding command line arguments:

#include "D:\opencv\build\include\opencv\cv.h"
#include "D:\opencv\build\include\opencv\highgui.h"

#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>

using namespace cv;
using namespace std;

int main()
{

//  string my_image;
    char my_image[100]="";
    cin>> my_image;
    Mat im = imread(my_image);

    if (im.empty()) 
    {
        cout << "Cannot load image!" << endl;
        return -1;
    }
    imshow("Image", im);
    waitKey(0);
}