Jay Patel
Jay Patel

Reputation: 1346

OpenCV window not able to load

I am working on the project for fingerprint matching and I am novice in using openCV library,

It is a simple code on displaying histogram which is present in the sample folder of openCV

int main(int, char** argv)
{
    Mat src, dst;

    /// Load image


    src = cv::imread("‪contour.jpg");
    cv::waitKey(5000);
    //waitKey(0);
    if (!src.data)
    {

        return -1;
    }

    /// Separate the image in 3 places ( B, G and R )
    ..
    vector<Mat> bgr_planes;
    split(src, bgr_planes);

    /// Establish the number of bins
    int histSize = 256;

    /// Set the ranges ( for B,G,R) )
    float range[] = { 0, 256 };
    const float* histRange = { range };

    bool uniform = true; bool accumulate = false;

    Mat b_hist, g_hist, r_hist;

    /// Compute the histograms:
    calcHist(&bgr_planes[0], 1, 0, Mat(), b_hist, 1, &histSize, &histRange, uniform, accumulate);
    calcHist(&bgr_planes[1], 1, 0, Mat(), g_hist, 1, &histSize, &histRange, uniform, accumulate);
    calcHist(&bgr_planes[2], 1, 0, Mat(), r_hist, 1, &histSize, &histRange, uniform, accumulate);

    // Draw the histograms for B, G and R
    int hist_w = 512; int hist_h = 400;
    int bin_w = cvRound((double)hist_w / histSize);

    Mat histImage(hist_h, hist_w, CV_8UC3, Scalar(0, 0, 0));

/// Normalize the result to [ 0, histImage.rows ]
    normalize(b_hist, b_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());
    normalize(g_hist, g_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());
    normalize(r_hist, r_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());

    /// Draw for each channel
    for (int i = 1; i < histSize; i++)
    {
        line(histImage, Point(bin_w*(i - 1), hist_h - cvRound(b_hist.at<float>(i - 1))),
            Point(bin_w*(i), hist_h - cvRound(b_hist.at<float>(i))),
        Scalar(255, 0, 0), 2, 8, 0);
        line(histImage, Point(bin_w*(i - 1), hist_h - cvRound(g_hist.at<float>(i - 1))),
            Point(bin_w*(i), hist_h - cvRound(g_hist.at<float>(i))),
        Scalar(0, 255, 0), 2, 8, 0);
        line(histImage, Point(bin_w*(i - 1), hist_h - cvRound(r_hist.at<float>(i - 1))),
            Point(bin_w*(i), hist_h - cvRound(r_hist.at<float>(i))),
            Scalar(0, 0, 255), 2, 8, 0);
    }

    /// Display
    namedWindow("calcHist Demo", WINDOW_AUTOSIZE);

    imshow("calcHist Demo", histImage);

    waitKey(0);

    return 0;

    }

I had kept the file contour.jpg in the same folder as that of cpp file.

I tried a lot but it shows following warning and the output window is not displayed.

I also tried to change the command argument variable, still no output.

'ConsoleApplication5.exe' (Win32): Loaded 'C:\Users\jaythegenius48\Documents\Visual Studio 2013\Projects\ConsoleApplication5\Debug\ConsoleApplication5.exe'. Symbols loaded.
'ConsoleApplication5.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. Symbols loaded.
'ConsoleApplication5.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Symbols loaded.
'ConsoleApplication5.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'. Symbols loaded.
'ConsoleApplication5.exe' (Win32): Loaded 'C:\opencv\build\x86\vc12\bin\opencv_core249.dll'. Cannot find or open the PDB file.
'ConsoleApplication5.exe' (Win32): Loaded 'C:\opencv\build\x86\vc12\bin\opencv_highgui249.dll'. Cannot find or open the PDB file.
'ConsoleApplication5.exe' (Win32): Loaded 'C:\opencv\build\x86\vc12\bin\opencv_imgproc249.dll'. Cannot find or open the PDB file.
'ConsoleApplication5.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp120d.dll'. Symbols loaded.

The program '[916] ConsoleApplication5.exe' has exited with code -1 (0xffffffff).

Your help will be appreciated, thank you

EDIT:Ok so here is the solution to my own Question:

1) I dont know what I did but I started with a new project .

2) Right click on your project, and then -> properties.

3) Depending upon your opencv directory( I suggest "C:\opencv" for windows),

make following changes in include directories and library directories (Select corresponding

folder). And I suggest using x86 folder even though u have 64 bit architecture.

Screenshot

4) Then following three Images:C/C++

Linker General

And Finally: Edit in Additional Dependancy

Add Following files in that text empty area.

Note:Depending upon your version of opencv filename will change, mine was 2.4.9 so it ends with 249 and for those who are using 2.4.3 would be 243 .

opencv_calib3d249d.lib    
opencv_contrib249d.lib    
opencv_core249d.lib    
opencv_features2d249d.lib    
opencv_flann249d.lib    
opencv_gpu249d.lib    
opencv_highgui249d.lib    
opencv_imgproc249d.lib    
opencv_legacy249d.lib    
opencv_ml249d.lib    
opencv_nonfree249d.lib    
opencv_objdetect249d.lib    
opencv_photo249d.lib    
opencv_stitching249d.lib    
opencv_ts249d.lib    
opencv_video249d.lib    
opencv_videostab249d.lib    

I hope this helps.Its frustrating but hardwork pays off.

Thanking the other members for answering my queries.

Upvotes: 4

Views: 6900

Answers (1)

DiJuMx
DiJuMx

Reputation: 524

Handling files is (in my opinion) one of the harder things to do. That is to say in terms of where to put them.

Try putting the image in the same directory as the executable, rather than the source.

Upvotes: 2

Related Questions