总之很邪门 在python下读取的视频帧率比C++下的要低 python 代码
import cv2
import numpy as np
cap = cv2.VideoCapture(1+cv2.CAP_DSHOW) #这里增加一个这,具体不知道是啥
# 设置摄像头分辨率
cap.set(6,cv2.VideoWriter_fourcc('M', 'J', 'P', 'G')) 设置读取视频的编码 必须写在其他设置##语句之前
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 2560)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)
c++代码:
#include <iostream>
#include <opencv2/highgui.hpp>
#include<opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main()
{
VideoCapture capture(1+CAP_DSHOW);
int width = 2560;
int hight = 720;
capture.set(CAP_PROP_FRAME_WIDTH, width);
capture.set(CAP_PROP_FRAME_HEIGHT, hight);
capture.set(CAP_PROP_FOURCC, VideoWriter::fourcc('M', 'J', 'P', 'G'));
Mat frame, zoomin;
cout << capture.get(CAP_PROP_FOURCC) << endl;
if (!capture.isOpened()) {
return -1;
}
char filename[200];
int count = 0;
while (1)
{
char key = cv::waitKey(20);
capture.read(frame);
resize(frame, zoomin, Size(width / 2, hight / 2), 0, 0, INTER_LINEAR);
imshow("video", zoomin);
if (key == 27) {
break;
}
if (key == 32) {
sprintf(filename, ".//img//lll%d.jpg", ++count);
imwrite(filename, frame);
imshow("image", frame);
}
}
return 0;
}