#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";
Child process the Father process
void *thread_function (void *arg) {
String Outputvideofile =output_video_file;
Videocapture videocapture (0);//Initialize Camera
if (!videocapture.isopened ()) {
cout << "Failed to open the default camera" << Endl;
return NULL;
}
/* Get the width and height of the video frame */
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;
/* Create a Videowriter object to write the video stream to a file */
Size framesize (static_cast<int> (framewidth), static_cast<int> (Frameheight));
/* Videowriter (output file name, output file encoding, frame rate, frame size, whether it is color (support win)) */
(' D ', ' I ', ' V ', ' X ') mp4
Videowriter Videowriter (Outputvideofile.c_str (), CV_FOURCC (' D ', ' I ', ' V ', ' X '), framesize, true);
if (!videowriter.isopened ()) {
cout << "Failed to initialize the Videowriter" << Endl;
return NULL;
}
while (true) {//Picture
Mat frame;
if (!videocapture.read (frame)) {//Hold, decode and return the next video frame
cout << "Failed to read a video frame" << Endl;
Break
}
Videowriter.write (frame); Frame written to File
if (= = = Waitkey (30)) {//wait for the "ESC" key to be pressed (note: Not working if no window is created!) )
cout << "ESC key pressed, stop capturing video" << Endl;
Break
}
}
return 0;
printf ("Child process%s\n", (char *) arg);
Pthread_exit ("Thank you for the CPU time");
}
int main (int argc, char *argv[]) {
pthread_t a_thread;//Thread ID
void *thread_result;
/* Create a thread with default properties */
if (Pthread_create (&a_thread, null,thread_function, (void *) argv[1]) < 0) {
Perror ("fail to Pthread_create");
Exit (-1);
}
printf ("Parent process \ n");
Waiting for thread to end (resource recycling)
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 Camera Thread