Sunday, November 17, 2013

OpenCV 2.4.7 - How to install and Create Sample Project in Visual Studio

Below are the sample programs


The program below is for opening webcam 

#include <opencv\cv.h>
#include <opencv\highgui.h>

using namespace cv;
int main(){


Mat image;

VideoCapture cap;
cap.set(CV_CAP_PROP_FRAME_WIDTH, 640);
cap.set(CV_CAP_PROP_FRAME_HEIGHT, 480);
cap.open(0);

namedWindow("window",1);
while(1)
{

 try
{
cap>>image;

 imshow("window",image);
 }
catch (Exception& e)
{
    const char* err_msg = e.what();
    std::cout << "exception caught: imshow:\n" << err_msg << std::endl;
}
 waitKey(33);
}

}



The program below is for opening an image

#include <opencv\cv.h>
#include <opencv\highgui.h>

using namespace cv;

int main(int argc, char** argv)
{
    IplImage* img = cvLoadImage( "image.png" ); //change the name (image.jpg) according to your Image filename.
    cvNamedWindow( "Example1", CV_WINDOW_NORMAL );
    cvShowImage("Example1", img);
    cvWaitKey(0);
    cvReleaseImage( &img );
    cvDestroyWindow( "Example1" );
    return 0;
}

Version 2.4.7 Additional Dependencies

opencv_core247d.lib
opencv_imgproc247d.lib
opencv_highgui247d.lib
opencv_ml247d.lib
opencv_video247d.lib
opencv_features2d247d.lib
opencv_calib3d247d.lib


41 comments:

  1. hello..could you please help me why I cant open the image? The pop window for display the image appear after the execution, but the image is blank..no exact image appear.just a blank image grey in colour.. What is the problem. I'm a newbie...

    ReplyDelete
    Replies
    1. I faced the same problem too. But then I copied pasted the required image into the working directory folder and removed the path from the program. It worked. Go to the visual studio projects folder and if the name of your project is demo then, projects\demo\demo\image.jpg. Paste it as explained.Try it, may be it ll help you.

      Delete
    2. hi..suppose if the image location is C:\opencv247 then in code write- IplImage* img = cvLoadImage( "C:\\opencv247\\image1.jpg" ); extra \ is given as escape sequence.

      Delete
    3. kavitha is right on the spot ..but what is going to take using for a path outside the app folder to work ?

      Delete
    4. getting same problem .....
      can any one solve this....

      Delete
    5. This comment has been removed by the author.

      Delete
    6. Add one backslash in the image name, like the video, for example: C:\\Desktop\\blackcar.jpg

      Delete
  2. sir the build was successful..however the image wsnt dislplayed..do v have to store the omage in visual studio beforehald or supply the complete url???

    ReplyDelete
  3. Very nice tutorial both program are running fine brother by following ur simple steps...waiting for more such tutorials on opencv how to opencv libraries....thank you very much

    ReplyDelete
  4. Thank you for your tutorial. It is really helpful for a beginner like me.

    ReplyDelete
  5. Thanks for the tutorial. this is the only tutorial out of 20 that got me started with opencv

    ReplyDelete
  6. Thank you for your awesome tutorial :)

    ReplyDelete
  7. Thank you so much :) It was very helpful!!

    ReplyDelete
  8. All outputs are up-to-date.
    1>LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt
    1>
    1>Build FAILED

    Tried several times..
    I even pasted the dll in the debug folder.
    Please help me...

    ReplyDelete
    Replies
    1. i had the same prob try this:
      Property Manager

      Double click Debug

      C/C++ -> General -> Additional Include Directories

      C:\OpenCV\install\include\opencv
      C:\OpenCV\install\include

      Linker -> General -> Additional Library Directories

      C:\OpenCV\install\lib

      Delete
    2. i was able to solve...
      by ...going to project properties->linker->general->enable incremental linking->No(set this to no) and it works

      Delete
    3. Shamim- BangladeshOctober 15, 2015 at 6:16 PM

      Thanks. It works for me.

      Delete
  9. thank you so much , i was able to solve...
    by ...going to project properties->linker->general->enable incremental linking->No(set this to no) and it works

    ReplyDelete
  10. when i build the program to open the web cam i m getting this error:
    fatal error LNK1169: one or more multiply defined symbols found
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    plz help

    ReplyDelete
  11. Thank you, so much!!! You're a genius! haha

    ReplyDelete
  12. #include
    #include

    using namespace cv;
    int main()
    {
    cvNamedWindow("Window", CV_WINDOW_AUTOSIZE);
    CvCapture* capture =cvCreateCameraCapture(-1);
    if (!capture){
    printf("Error. Cannot capture.");
    }
    else{
    cvNamedWindow("Window", CV_WINDOW_AUTOSIZE);

    while (1){
    IplImage* frame = cvQueryFrame(capture);
    if(!frame){
    printf("Error. Cannot get the frame.");
    break;
    }
    cvShowImage("Window",frame);
    char c = cvWaitKey(33);
    if( c == 27 ) break;
    }
    cvReleaseCapture(&capture);
    cvDestroyWindow("Window");
    }
    return 0;
    }


    i tried to capture image from webcam and display in the window but it is showing window without image.can you give solution for this problem

    ReplyDelete
  13. Hello,
    I followed the steps through the video and trying to open an image file but when I start debugging I got unresolved external symbol errors. I also tried to copy the correspondent dll-s into the project folder but no use. How can I resolve this issue?

    ReplyDelete
  14. Sir, There's a system error appeared when the time I run it. "The Program can't start because MSVCP120D.dll is missing from you computer. Try reinstalling the program to fix this problem." What should I do to make it work sir?

    ReplyDelete
  15. Superb video. Too bad there isn't one for 2.4.6 and VS 2013 c++.. There are differences between the IDEs. Still, quite helpful.

    N. Calif, USA

    ReplyDelete
  16. so good..everything is very clear.. Your are good mentor.
    Can anyone provide me any good documentation that help me to learn opencv?

    ReplyDelete
  17. Thank you so much its working very nicely and great job.

    ReplyDelete
  18. hello i have problem when i exeute the program and the error masseage is :
    The program can't start because opencv_core248d.dll is missing from your computer. try reinstalling the program to fix this problem

    ReplyDelete
    Replies
    1. I got the same problem then I pasted dll from opencv\build\x86\vc12\bin folder , but then another error it started showing cant find MSVCP120D.dll

      anyone can help ?

      Delete
  19. I followed exactly the way you described in your youtube video "How to install OpenCV 2.4.7 and Create Sample Project in Visual...", however I am getting an error
    saying opencv_core248d.dll is missing from your computer.
    Kindly help me resolve the issue
    thanks

    ReplyDelete
  20. Morever, I am using visual studio 13...

    ReplyDelete
  21. Yeah its a good article. According to you what we project managers do is communicating. And a lot of this communication is done during project meetings. It can sometimes feel like you are running from one meeting to another and that your time is often wasted. Meetings don’t start on time, the issues aren’t dealt with, there is no agenda, there is no focus, nobody assigns any follow ups or tasks and of course then they also don’t end on time. An efficient project manager is required for the good management of a project. I think a project manager should PMP certified. Looking forwards to apply what I learned in PMP classes in my company.

    ReplyDelete
  22. When I try to build it says
    Error 1 error LNK1181: cannot open input file 'opencv_calib3d300d.lib' c:\Users\--\documents\visual studio 2013\Projects\OPEN_CV_TEST\OPEN_CV_TEST\LINK OPEN_CV_TEST

    I followed the instructions carefully.. Using visual studio 2013 please help!

    ReplyDelete
    Replies
    1. got the exact same prob ..followed different tuts really carefully...though its 3.0..and im using x64

      Delete
  23. please help. working for two days:

    having the following error can't fix.

    1>LINK : fatal error LNK1104: cannot open file 'opencv_core2410d.lib'

    also my lib folder does not have .lib extension files

    ReplyDelete
  24. I am using opencv2.4.10 , visual studio 2010 , having 64 bit operating system
    thanks in advance

    ReplyDelete
  25. some one can help me to write the programe to implements the segmentation region growing method please help me

    ReplyDelete
  26. very nice tutorial :) . ,but i want to interface opencv with processing software....i tried hard but couldn't. Can u please tell me how to interface opencv with processing.
    Thank you

    ReplyDelete
  27. NOTE~!
    After add path to Environment Variables, you must restart PC

    ReplyDelete
  28. the webcam program is showing 20 errors.it says "VideoCapture" is undefined along with with "namedWindow" . Plz give the solution asap.

    ReplyDelete
  29. Hello,
    The build was successful but while debug getting error...."Unable to start program"project name", the system can't find the file specified"

    ReplyDelete