发布时间:2023-04-01 10:30
#include
using namespace cv;
int main(int argc,char *argv[])
{
char ch[10] = {'W','A','N','G',' ','T','E','S','T','\0'};
char te[100] = "test opencv camera";
//从硬盘上打开视频
cv::VideoCapture capture;
capture.open(argv[1]);
//循环显示每一
Mat frame,gray;//定义一个Mat变量,用于存储每一的图像
Size size = Size(capture.get(CV_CAP_PROP_FRAME_WIDTH), capture.get(CV_CAP_PROP_FRAME_HEIGHT));
VideoWriter writer;
writer.open("final.avi", CV_FOURCC('M', 'J', 'P', 'G'), 10, size, true);
cv::Point p = cv::Point(10, 400);
while (capture.read(frame))
{
// capture>>frame;//读取当前帧
// cvtColor(frame,gray,COLOR_BGR2GRAY);
//二值化处理
//threshold(gray, gray, 0, 255, THRESH_BINARY | THRESH_OTSU);
// cvtColor(gray, gray, COLOR_GRAY2BGR);
putText(frame, te, p, FONT_HERSHEY_SIMPLEX, 2, Scalar(0, 100, 100), 2, CV_AA);
imshow("读取视频帧",frame);//显示当前顿
writer.write(frame);
waitKey(200);//延时30ms
}
system("pause");
return 0;
}
编译
g ++ -o test_1 test_1.cpp`pkg-config opencv --cflags --libs`
执行
./test /dev/video0
结果