#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 摄像头 线程的更多相关文章

  1. Opencv摄像头实时人脸识别

    Introduction 网上存在很多人脸识别的文章,这篇文章是我的一个作业,重在通过摄像头实时采集人脸信息,进行人脸检测和人脸识别,并将识别结果显示在左上角. 利用 OpenCV 实现一个实时的人脸 ...

  2. OpenCV摄像头人脸识别

    注: 从外设摄像装置中获取图像帧,把每帧的图片与人脸特征进行匹配,用方框框住识别出来的人脸 需要用到的函数: CvHaarClassifierCascade* cvLoadHaarClassifier ...

  3. Opencv 摄像头矫正

    摄像机有6个外参数(3个旋转,3个平移),5个内参数(fx,fy,cx,cy,θ),摄像机的内参数在不同的视场,分辨率中是一样的,但是不同的视角下6个外参数是变化的,一个平面物体可以固定8个参数,(为 ...

  4. Android+OpenCV 摄像头实时识别模板图像并跟踪

    通过电脑摄像头识别事先指定的模板图像,实时跟踪模板图像的移动[用灰色矩形框标识] ps:一开始以为必须使用OpenCV Manager,可是这样会导致还需要用户去额外安装一个apk,造成用户体验很差, ...

  5. 【转载】OpenCV 摄像头控制

    参考:[OpenCV] -- 简单摄像头操作 - 代码人生 - 博客频道 - CSDN.NET http://blog.csdn.net/qiurisuixiang/article/details/8 ...

  6. opencv 摄像头人脸检测

    PYTHON ubuntu16.04 默认安装的Python版本2.7.12,当用pip install opencv-python 安装了opencv for python 3.3.0.10后,运行 ...

  7. opencv:摄像头和视频的读取

    示例代码: #include <opencv.hpp> using namespace cv; int main() { VideoCapture Capture(); //打开默认摄像头 ...

  8. OpenCV摄像头读取

    在Mac下面使用默认的OpenCV读取摄像头程序会报错 int main(int, char**) { VideoCapture cap(0); // open the default camera ...

  9. opencv摄像头捕获图像

    #include <iostream> #include <opencv2/opencv.hpp> using namespace cv; using namespace st ...

随机推荐

  1. hdu 3665Seaside(简单floyd)

    Seaside Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Su ...

  2. mysql的水平拆分和垂直拆分 (转)

    http://www.cnblogs.com/sns007/p/5790838.html 1,水平分割: 例:QQ的登录表.假设QQ的用户有100亿,如果只有一张表,每个用户登录的时候数据库都要从这1 ...

  3. css文件放在根目录之后不起作用原因

    修改为

  4. MySQL连接数过多登录不上

    [mysqld_safe]socket          = /var/run/mysqld/mysqld.socknice            = 0 [mysqld]## * Basic Set ...

  5. (纪录片)你必须知道的科学 The Science That You Have To Know (2014)

    简介: 类型: 纪录片制片国家/地区: 英国语言: 英语上映日期: 2014-2片长: 150分钟 主要内容: 你有没有认真想过,自己的身体有多奇妙?人体是世间最复杂的一项工程杰作,他也带来了一些非常 ...

  6. 通过项目逐步深入了解Mybatis<一>

    Mybatis Mybatis 和 SpringMVC 通过订单商品案例驱动 官方中文地址:http://www.mybatis.org/mybatis-3/zh/ 官方托管地址:https://gi ...

  7. apache 反向代理的时候,通过域名访问是,出现跳转到ip或者无权访问的情况

    解决方法很简单,在配置反向代理的时候加上一行: ProxyPreserveHost On 例如:ProxyPass / http://202.112.0.1/ProxyPassReverse / ht ...

  8. python unittest case运行失败重试

    因为使用unittest进行管理case的运行.有时case因为偶然因素,会随机的失败.通过重试机制能够补充保持case的稳定性.查阅资料后发现,python的unittest自身无失败重试机制,可以 ...

  9. 使用迭代器遍历List的时候修改List报ConcurrentModificationException异常原因分析

    在使用Iterator来迭代遍历List的时候如果修改该List对象,则会报java.util.ConcurrentModificationException异常,下面看一个例子演示: package ...

  10. 【转】Flash:同志们,这些知识点你们知道多少?(一些必备的Flash开发知识点)

    1.理解flash的显示列表                2.理解事件冒泡,理解鼠标事件等        3.理解flash的性能瓶颈和大多数影响性能的地方4.理解帧跑道模型,知道timer和ent ...