4

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.

Emil Laine
  • 41,598
  • 9
  • 101
  • 157
Jay Patel
  • 1,266
  • 6
  • 20
  • 38
  • 2
    "and the output window is not displayed." - i can't see any code, that would display something in a window. – berak Apr 19 '14 at 15:31
  • 3
    it did not find your image, and returned -1. all well, no error. – berak Apr 19 '14 at 15:33
  • 2
    I had kept the image in same directory.And yes I edited the code. – Jay Patel Apr 19 '14 at 15:36
  • see, your prog will stop before doing anything, unless it loads the image. so either adjust the working dir in your ide, or try an absolute path for the image. – berak Apr 19 '14 at 15:39
  • 2
    Thanx for your precious comments, I tried every possible thing, but the same result. – Jay Patel Apr 19 '14 at 15:46

1 Answers1

2

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.

DiJuMx
  • 524
  • 5
  • 10
  • 3
    now it shows Error " error LNK1104: cannot open file 'opencv_haartraining_engined.lib' ". – Jay Patel Apr 19 '14 at 16:17
  • 2
    Which files I have to link in my property sheets of debug and release.I managed to link files ending with "..d.lib" in debug linker and others in release linker from the C:\opencv\build\x86\vc12\lib directory. – Jay Patel Apr 19 '14 at 16:18
  • 1
    That sounds like a completely different error relating to your environment setup. Are you able to compile other OpenCV programs? – DiJuMx Apr 19 '14 at 16:36
  • 2
    No I am not.Now I am sure that the problem is in linker files, now it shows Error "error LNK1181: cannot open input file 'opencv_haartraining_engined.lib'" , Can you tell me exactly which files to be linked in debug in release? – Jay Patel Apr 19 '14 at 16:39
  • 1
    Unfortunately, I can't as I don't use Visual Studio (or Windows for that matter). However, a quick Google search gives instructions from the [opencv website](http://docs.opencv.org/doc/tutorials/introduction/windows_visual_studio_Opencv/windows_visual_studio_Opencv.html), [stack overflow](http://stackoverflow.com/questions/20835470/opencv-link-fatal-error-lnk1104-cannot-open-file-opencv-haartraining-engine), and another [stack overflow](http://stackoverflow.com/questions/20835470/opencv-link-fatal-error-lnk1104-cannot-open-file-opencv-haartraining-engine) – DiJuMx Apr 19 '14 at 16:52