Compile OpenCV with MinGW 4.5.2 under Windows 2.3.0

Source: Internet
Author: User

The tools you need:
1. Installing the QT SDK Environment
2. Install CMake for Windows
3, OpenCV the latest Windows source code
Steps:
1. Add {Qtsdk}\mingw\bin to the System environment variable path in the QT SDK installation directory
2, open CMake, set source location and source code construction location

3, click Configure, select the following

5, Configuer after generate
6, through the MinGW shell into the D:/opencv execution Mingw32-make makefile compilation, Mingw32-make install
7, after completion of D:/opencv Lib, bin directory will generate a library file, at this time we can be lib, bin directory, add source in the Include directory to a separate directory, these constitute the OPENCV SDK
8. Open QT creater Create a QT empty project, modify the Pro file to add OpenCV include and Lib

    1. Includepath += D:\OpenCV\include
    2. LIBS += D:\OpenCV\lib\*. A

9, create C + + source files, add the following code

  1. #include <Highgui. H>// contains OPENCV library header file
  2. #include <CV. H>
  3. int main( int argc, Char** argv ) { // main function
  4. Cvnamedwindow( "Example2", cv_window_autosize ); / / Create window, (first name, default size)
  5. Cvcapture *capture = NULL; / / video capture structure, used as a parameter of the video acquisition function
  6. Capture = cvcreatecameracapture(0); / / turn on the camera and get the video from the camera
  7. Iplimage* frame; / / application iplimage type pointer, is to request memory space to hold each frame image
  8. while (1) {
  9. Frame = cvqueryframe( capture ); / / fetch from the camera and return each frame
  10. if ( ! Frame )
  11. Break;
  12. Cvshowimage( "Example2", frame ); / / Display each frame on the window
  13. char c = Cvwaitkey(+); / / delay, about 33 frames per second, according to the human eye viewing speed;
  14. if ( c == )
  15. Break; / / due to a dead loop, and no console, when pressing the keyboard exc key, exit the loop;
  16. }
  17. Cvreleasecapture( &capture ); / / free memory;
  18. Cvdestroywindow( "Example2" ); / / Destroy window
  19. }

10, the compiler after the implementation of the error, this is due to the lack of DLLs, the compiled OPENCV after the successful bin directory to add to the system paht or copy to the project directory, the successful call again

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.