#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. 转: git使用时让http记住帐号密码

    见 http://git.mydoc.io/?t=154710 https 方式每次都要输入密码,按照如下设置即可输入一次就不用再手输入密码的困扰而且又享受 https 带来的极速 按照以下设置记住密 ...

  2. w3cscholl的在线代码编辑工具2

    https://www.w3cschool.cn/tryrun/runcode?lang=c

  3. (转)最近一个项目中关于NGUI部分的总结(深度和drawCall)

    在自己最近的一个项目中,软件的界面部分使用了NGUI来进行制作.在制作过程中,遇到了一些问题,也获取了一些经验,总结下来,作为日后的积累. 1.NGUI图集的使用. 此次是第一个自己正儿八经的制作完整 ...

  4. 命令行下从bak文件恢复sqlserver数据库方法

    命令行下从bak文件恢复sqlserver数据库方法 注:本文所示访问从SqlServer 2000 - 2014版都是通用的 参考:http://blog.sina.com.cn/s/blog_5c ...

  5. php manager

    https://phpmanager.codeplex.com/releases/view/69115

  6. Bossies 2015: The Best of Open Source Software Awards

    InfoWorld editors and contributors pick the top open source software for data centers, clouds, devel ...

  7. iOS 根据圆心的坐标点、半径、当前手势所在的坐标点,计算出圆的运动轨迹坐标

    /** * 根据圆心的坐标点.半径.当前手势所在的坐标点,计算出圆的运动轨迹坐标 * @param radius 圆心半径 * @param centerCircle 圆心的坐标点 * @param ...

  8. JAVA中动态编译的简单使用

    一.引用库 pom文件中申明如下: <dependencies> <!-- https://mvnrepository.com/artifact/junit/junit --> ...

  9. Linux安装pear包

    一.安装pear包. 1.安装: $ sudo wget http://pear.php.net/go-pear.phar $ sudo php go-pear.har 2.查看pear下安装的包: ...

  10. ES6学习笔记十一:编程风格技巧

    一:用let取代var 二:静态字符串一律使用单引号或反引号,不使用双引号.动态字符串(模版字符串)使用反引号. 三:解构赋值: 使用数组对变量赋值时,优先使用解构赋值: 函数的参数如果是对象的成员, ...