#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. MODBUS协议整理——功能码简述

    1.Modbus简介——来自维基百科 Modbus是一种串行通信协议,是Modicon于1979年,为使用可编程逻辑控制器(PLC)而发表的.Modbus是工业领域通信协议的业界标准,并且现在是工业电 ...

  2. Direct2D教程VII——变换几何(TransformedGeometry)对象

    目前博客园中成系列的Direct2D的教程有 1.万一的 Direct2D 系列,用的是Delphi 2009 2.zdd的 Direct2D 系列,用的是VS中的C++ 3.本文所在的 Direct ...

  3. .NET 开发套装

    Dapper,轻量级ORM GitHub - StackExchange/dapper-dot-net: DapperSharpZipLib,ZIP压缩库 SharpZipLib by icsharp ...

  4. 【Python】安装geocoder

    C:\Users\horn1\Desktop\python\49-geo>pip install geocoder Collecting geocoder Downloading https:/ ...

  5. 微服务架构实践 - 你只懂docker与spring boot就够了吗?

    微服务架构实践 - 你只懂docker与spring boot就够了吗? 作者 浮云发发 已关注 2017.02.27 02:50* 字数 2613 阅读 2583评论 6喜欢 35赞赏 2 微服务并 ...

  6. iOS编程(双语版) - 视图 - Transform(转换)

    视图有一个transform属性,它描述了应该如何绘制该视图. 该属性是CGAffineTransform结构体,它代表了3 x 3的变换矩阵(线性代数). 下面的代码让两个矩形视图旋转45度 (Ob ...

  7. jQuery最简单的表单提交方式

    第一步:绑定事件 常用的与ajax相关的事件参考如下: 1.$(selector).click(function) 2.$(selector).change(function) 3.$(selecto ...

  8. ZH奶酪:PHP 执行时间Fatal error: Maximum execution time of...

    来源:http://stackoverflow.com/questions/5164930/fatal-error-maximum-execution-time-of-30-seconds-excee ...

  9. JQuery 之 动态加载JS或JS文件

    如果用jquery的append直接加载script标签的话,会报错的. 1.可以用 document.write() 实现加载动态JS代码. 2.可以用 getScript() 函数实现加载JS文件 ...

  10. C#中使用RabbitMQ收发队列消息

    一.程序使用NetCore.引入Nuget: Install-Package RabbitMQ.Client -Version 4.1.3 二.消息发部端: using RabbitMQ.Client ...