Computer Vision Library for compiling Python3 under 64-bit Win7: OpenCV

Source: Internet
Author: User

  

 Note: This article is all original, ZMAN (http://www.cnblogs.com/zmanone/)

OPENCV is currently the latest version of 3.0.0 RC1, the official gave the compilation of good Python2 can be used directly cv2.pyd, but I want to use in Python3! Can only bite the bullet himself compiled, MinGW compiled to the last step failed, and eventually compiled with Visual Studio 2012 successful, the process is shared as follows:

  (Note ①: This step applies to WIN7 64-bit operating system, Python version is 3.4.3 64BIT,OPENCV version 3.0.0 RC1, my Cuda version is 5.5)

(Note ②: Make sure the numpy!! is installed )

1. Install Visual Studio 2012. (Link: http://pan.baidu.com/s/1nt65Oet password: asiu serial number: YKCW6-BPFPF-BT8C9-7DCTH-QXGWC)

2. Install the CMake. (Link: http://pan.baidu.com/s/1c0EVLfE password: MXQF)

3. Download OpenCV source code. Unzip to any location, such as my is "D:/opencvcode" (Link: Http://pan.baidu.com/s/1gdvSHuN password: FABQ)

Optionally, download the OPENCV extension modules package. Unzip to any location, such as my is "D:/opencv_contrib-master" (Link: Http://pan.baidu.com/s/1c0tqZ9A password: ee71)

4. Modify the code.

① open "D:\opencvcode\sources\modules\python\src2\hdr_parser.py".

      in line 4th, import the codecs library, and the No. 737 line is "F = codecs.open (Hname," R "," Utf-8 ").

② open "D:\opencvcode\sources\cmake\OpenCVCompilerOptions.cmake".

      comment out the 67th line "add_extra_compiler_option (-werror=non-virtual-dtor)" (with the first comment: #).

③ open "D:\opencvcode\sources\modules\python\common.cmake".

      add a line under line 27th, "# Header Blacklist": Ocv_list_filterout (Opencv_hdrs "Detection_based_tracker").

5. Compile the source code.

① Open CMake (GUI), "where is the source code" locates to "d:/opencvcode/sources" directory, "where to build the binaries" locates to any output folder, for example my is "D: /opencv1 ".

② tick "grouped" and "advanced".

③ Click "Configure", OK, the compiler selects "Visual Studio Win64".

④ make sure the "BUILD-and-Build_opencv_python3" is checked, do not tick "with-and With_ipp", please check the "PYTHON3" under the various path, DIR, library path is not correct.

⑤ do not tick "Build_opencv_line_descriptor" and "saliency". (I don't know what the two libraries are for, but I can't compile them after I tick the Line_descriptor)

⑥ "OPENCV, Opencv_extra_modules_path" to "D:/opencv_contrib-master/modules".

⑦ Click "Configure" again to make sure that there is no red background color option, click "Generate".

6. Build code.

① enter "D:/OPENCV1" and Open "OpenCV.sln".

② switch to "Release" mode, right-click "Solution ' OpenCV '" select "Rebuild Solution", followed by a long wait, if the last display of the number of failures is 0, success!

7. Set environment variables.

① Add the "d:/opencv1/bin/release" directory to the environment variable and copy "D:/opencv1/lib/release/cv2.pyd" to the "Site-packages" folder in your Python directory.

8. Taste the joy of success.

① in Python, run the following code:

      

ImportCv2ImportNumPy#Read in Imageim = Cv2.imread ('c:/users/public/pictures/sample pictures/koala.jpg')#Down samplingIm_lowres =Cv2.pyrdown (IM)#Convert to Grayscale imageGray =Cv2.cvtcolor (Im_lowres, Cv2. Color_rgb2gray)#detect feature pointss=cv2.xfeatures2d.SURF_create ()#s = cv2. SURF ()Mask =numpy.uint8 (Numpy.ones (gray.shape)) keypoints=S.detect (Gray, mask)#displaying images and feature pointsVis =Cv2.cvtcolor (Gray, Cv2. COLOR_GRAY2BGR) forKinchKeypoints[::10]: cv2.circle (Vis, (int (k.pt[0)), int (k.pt[1]), 2, (0, 255, 0), 1) cv2.circle (Vis, (int (k.pt[0)), int (k.pt[1])), int (k.size), (0, 255, 0), 2) Cv2.imshow ('Local descriptors', Vis) Cv2.waitkey () Cv2.imwrite ('c:/users/public/pictures/sample pictures/koala2.jpg', Vis)

②duang~ jumping out of a picture like this koala shows success!!

Computer Vision Library for compiling Python3 under 64-bit Win7: OpenCV

Related Article

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.