python3下opencv的编译过程

1. 必备准备

  • opencv源码
  • cmake
  • vs 2015
  • Anaconda3 64bit

2. 构建过程

将上述软件部署到位后,打开cmake,设定源码目录与编译目录后点击configure。python3下opencv的编译过程_第1张图片

由于安装的是64位Anaconda3,所以这里需要选择vs 2015 win64。
等待配置结束后,确认待构建目录有

如果没有python3项,说明python路径设置有问题,参考下图
python3下opencv的编译过程_第2张图片
然后再次configure,若有报错信息,需要根据信息内容针对性取消相关模块。完成后点击Generate。在构建目录下会产生OpenCV.sln文件,用vs2015打开。python3下opencv的编译过程_第3张图片
1. 解决方案配置选择Release。
2. 右击解决方案OpenCV,重新生成解决方案。等待完成。
编译成功后:
1. 添加D:\OpenCV\opencv\build\bin\Release到环境变量中。
2. 将D:\OpenCV\opencv\build\lib\python3\Release目录下的pyd重命名为cv2.pyd拷贝到anaconda3\lib\site-packages目录下。即可大功搞成。

视频播放代码

# 处理没有问题
import cv2
cap = cv2.VideoCapture('D:\\image_resource\Stellar.avi')

# Define the codec and create VideoWriter object

while(True):
    # Capture frame-by-frame
    ret, frame = cap.read()
    # Our operations on the frame come here
    # gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    # Display the resulting frame
    # cv2.imshow('frame',gray)
    cv2.imshow('frame',frame)
    if cv2.waitKey(30) & 0xFF == ord('q'):
        break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()

你可能感兴趣的:(opencv)