opencv 摄像头 线程
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <iostream>
#include <unistd.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <semaphore.h>
#include <sys/shm.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <sys/stat.h>
#include "opencv.hpp"
#include <fcntl.h>
#include <errno.h>
#include <ctype.h>
#define OUTPUT_VIDEO_FILE "webcam.avi"
#define OUTPUT_VIDEO_FILE1 "webcam1.avi"
#define OUTPUT_VIDEO_FILE2 "a.k"
using namespace std;
using namespace cv;
char message[32] = "Hello World";
//子进程 先父进程
void *thread_function(void *arg){
string outputVideoFile =OUTPUT_VIDEO_FILE;
VideoCapture videoCapture(0); //初始化摄像头
if (!videoCapture.isOpened()){
cout << "Failed to open the default camera" << endl;
return NULL;
}
/* 获取视频帧的宽度和高度 */
double frameWidth = videoCapture.get(CV_CAP_PROP_FRAME_WIDTH);
double frameHeight = videoCapture.get(CV_CAP_PROP_FRAME_HEIGHT);
cout << "Frame size is [" << frameWidth << "x" << frameHeight << "]" << endl;
/* 创建一个VideoWriter的对象将视频流写入文件 */
Size frameSize(static_cast<int>(frameWidth), static_cast<int>(frameHeight));
/* videoWriter(输出的文件名,输出文件的编码,帧率,帧的尺寸,是否是彩色(尽支持win)) */
//('D', 'I', 'V', 'X') mp4
VideoWriter videoWriter(outputVideoFile.c_str(), CV_FOURCC('D', 'I', 'V', 'X'), 20, frameSize, true);
if (!videoWriter.isOpened()){
cout << "Failed to initialize the VideoWriter" << endl;
return NULL;
}
while(true){ //图片
Mat frame;
if (!videoCapture.read(frame)){ // 抓住,解码并返回下一个视频帧
cout << "Failed to read a video frame" << endl;
break;
}
videoWriter.write(frame); //写入文件的框架
if(27 == waitKey(30)){ //等待按下“ESC”键(注意:不是工作如果没有窗口被创建!)
cout << "ESC key pressed, stop capturing video" << endl;
break;
}
}
return 0;
printf("子进程 %s\n", (char *)arg);
//pthread_exit("Thank you for the cpu time");
}
int main(int argc, char *argv[]){
pthread_t a_thread; //线程id
void *thread_result;
/*使用缺省属性创建线程*/
if (pthread_create(&a_thread, NULL,thread_function, (void *)argv[1]) < 0){
perror("fail to pthread_create");
exit(-1);
}
printf("父进程\n");
// 等待线程结束(资源回收)
if (pthread_join(a_thread, &thread_result) < 0){
perror("fail to pthread_join");
exit(-1);
}
printf("MESSAGE is now %s\n", message);
return 0;
}
opencv 摄像头 线程的更多相关文章
- Opencv摄像头实时人脸识别
Introduction 网上存在很多人脸识别的文章,这篇文章是我的一个作业,重在通过摄像头实时采集人脸信息,进行人脸检测和人脸识别,并将识别结果显示在左上角. 利用 OpenCV 实现一个实时的人脸 ...
- OpenCV摄像头人脸识别
注: 从外设摄像装置中获取图像帧,把每帧的图片与人脸特征进行匹配,用方框框住识别出来的人脸 需要用到的函数: CvHaarClassifierCascade* cvLoadHaarClassifier ...
- Opencv 摄像头矫正
摄像机有6个外参数(3个旋转,3个平移),5个内参数(fx,fy,cx,cy,θ),摄像机的内参数在不同的视场,分辨率中是一样的,但是不同的视角下6个外参数是变化的,一个平面物体可以固定8个参数,(为 ...
- Android+OpenCV 摄像头实时识别模板图像并跟踪
通过电脑摄像头识别事先指定的模板图像,实时跟踪模板图像的移动[用灰色矩形框标识] ps:一开始以为必须使用OpenCV Manager,可是这样会导致还需要用户去额外安装一个apk,造成用户体验很差, ...
- 【转载】OpenCV 摄像头控制
参考:[OpenCV] -- 简单摄像头操作 - 代码人生 - 博客频道 - CSDN.NET http://blog.csdn.net/qiurisuixiang/article/details/8 ...
- opencv 摄像头人脸检测
PYTHON ubuntu16.04 默认安装的Python版本2.7.12,当用pip install opencv-python 安装了opencv for python 3.3.0.10后,运行 ...
- opencv:摄像头和视频的读取
示例代码: #include <opencv.hpp> using namespace cv; int main() { VideoCapture Capture(); //打开默认摄像头 ...
- OpenCV摄像头读取
在Mac下面使用默认的OpenCV读取摄像头程序会报错 int main(int, char**) { VideoCapture cap(0); // open the default camera ...
- opencv摄像头捕获图像
#include <iostream> #include <opencv2/opencv.hpp> using namespace cv; using namespace st ...
随机推荐
- xgboost入门与实战(实战调参篇)
https://blog.csdn.net/sb19931201/article/details/52577592 xgboost入门与实战(实战调参篇) 前言 前面几篇博文都在学习原理知识,是时候上 ...
- 个基于TensorFlow的简单故事生成案例:带你了解LSTM
https://medium.com/towards-data-science/lstm-by-example-using-tensorflow-feb0c1968537 在深度学习中,循环神经网络( ...
- 如何在原生工程中引入Cordova工程-for iOS 【转】
http://blog.csdn.net/e20914053/article/details/50170487 如今混合开发方兴未艾,有的项目可能一开始是原生开发的,后期需要加入混合开发,如将Cord ...
- GL_ACTIVE_UNIFORMS可能不会返回没有用到的uniform
To query for the list of active uniforms in a program, you first call glGetProgramiv with the GL_ACT ...
- [Go] Returning Multiple Values from a Function in Go
Returning multiple values from a function is a common idiom in Go, most often used for returning val ...
- Python 各种测试框架简介
转载:https://blog.csdn.net/yockie/article/details/47415265 一.doctest doctest 是一个 Python 发行版自带的标准模块.本篇将 ...
- Rainmeter 一部分 语法 中文教程
;Meter基本元素示例:;如果是[MeterStyle]表示Meter的公共Style,类似CSS的意义!!!;颜色可以使用网页的颜色定义方式,如半透明黄色:255.255.0.128=FFFF00 ...
- php学习实例3
新闻发布管理系统 路由器action.php <!DOCTYPE html> <html> <head> <title> </title> ...
- Android 之 assets目录和raw目录
Android 中存在assets目录和raw目录,它们既有相似之处又有所不同.一.共同点: 目录下的资源会被原封不动的拷贝到APK中,而不会像其它资源文件那样被编译成二进制的形式. 二.区别 1.最 ...
- Selenium2(WebDriver)总结(一)---启动浏览器、设置profile&加载插件
本文主要记录下在使用selenium2/webdriver时启动各种浏览器的方法.以及如何加载插件.定制浏览器信息(设置profile)等 环境搭建可参考我的另一篇文章:http://www.cnbl ...