camcv vid1.cpp

Download Camcv Vid1.Cpp

If you can't read please download the document

Upload: wiliam-javier

Post on 24-Nov-2015

80 views

Category:

Documents


5 download

TRANSCRIPT

///////////////////////////////////////////////////////////// // Many source code lines are copied from RaspiVid.c // Copyright (c) 2012, Broadcom Europe Ltd // // Lines have been added by Pierre Raufast - June 2013 // [email protected] // to work with OpenCV 2.3 // visit thinkrpi.wordpress.com // Enjoy ! // How to do face detection with your Raspberry Pi Camera module and OpenCV // // For a better world, read Giono's Books // ///////////////////////////////////////////////////////////// #include #include #include #include

//new #include #include #include "time.h" extern "C" { #include "bcm_host.h" #include "interface/vcos/vcos.h" #include #include #include #include #include #include #include "interface/mmal/mmal.h" "interface/mmal/mmal_logging.h" "interface/mmal/mmal_buffer.h" "interface/mmal/util/mmal_util.h" "interface/mmal/util/mmal_util_params.h" "interface/mmal/util/mmal_default_components.h" "interface/mmal/util/mmal_connection.h"

#include "RaspiCamControl.h" #include "RaspiPreview.h" #include "RaspiCLI.h" } #include // OPENCV #include #include #include #include "time.h" #include #include #include #include #include #include "opencv2/core/core.hpp" "opencv2/contrib/contrib.hpp" "opencv2/highgui/highgui.hpp" "opencv2/imgproc/imgproc.hpp" "opencv2/objdetect/objdetect.hpp" "/home/pi/pierre/libfacerec-0.04/include/facerec.hpp" // faces; // nb of picture learnt by people int nPictureById[MAX_PEOPLE]; /////////////////////// /// Camera number to use - we only have one camera, indexed from 0. #define CAMERA_NUMBER 0 // Standard port setting for the camera component #define MMAL_CAMERA_PREVIEW_PORT 0 #define MMAL_CAMERA_VIDEO_PORT 1 #define MMAL_CAMERA_CAPTURE_PORT 2 // Video format information #define VIDEO_FRAME_RATE_NUM 30 #define VIDEO_FRAME_RATE_DEN 1 /// Video render needs at least 2 buffers. #define VIDEO_OUTPUT_BUFFERS_NUM 3 // Max bitrate we allow for recording const int MAX_BITRATE = 30000000; // 30Mbits/s

// variable to convert I420 frame to IplImage int nCount=0; IplImage *py, *pu, *pv, *pu_big, *pv_big, *image,* dstImage; int mmal_status_to_int(MMAL_STATUS_T status); /** Structure containing all state information for the current run */ typedef struct { int timeout; /// Time taken before frame is grabbed an d app then shuts down. Units are milliseconds int width; /// Requested width of image int height; /// requested height of image int bitrate; /// Requested bitrate int framerate; /// Requested frame rate (fps) int graymode; /// capture in gray only (2x faster) int immutableInput; /// Flag to specify whether encoder works in place o r creates a new buffer. Result is preview can display either /// the camera output or the encoder outp ut (with compression artifacts) RASPIPREVIEW_PARAMETERS preview_parameters; /// Preview setup parameters RASPICAM_CAMERA_PARAMETERS camera_parameters; /// Camera setup parameters MMAL_COMPONENT_T *camera_component; MMAL_COMPONENT_T *encoder_component; MMAL_CONNECTION_T *preview_connection; era to preview MMAL_CONNECTION_T *encoder_connection; era to encoder /// Pointer to the camera component /// Pointer to the encoder component /// Pointer to the connection from cam /// Pointer to the connection from cam

MMAL_POOL_T *video_pool; /// Pointer to the pool of buffers used by encoder o utput port } RASPIVID_STATE; /** Struct used to pass information in encoder port userdata to callback */ typedef struct { FILE *file_handle; /// File handle to write buffer data to. VCOS_SEMAPHORE_T complete_semaphore; /// semaphore which is posted when we re ach end of frame (indicates end of capture or fault) RASPIVID_STATE *pstate; /// pointer to our state in case required in callback } PORT_USERDATA; //////////////////////////////////////// ///////////////////////////////////////////////// // trace if TRACE==1 ///////////////////////////////////////////////// void trace(string s) { if (TRACE==1) { coutMAX_PEOPLE;i++) { nPictureById[i]=0; } int bFirstDisplay =1; trace("(init) People initialized"); // Get the path to your CSV fn_csv = string(argv[1]); // Note : /!\ change with your opencv path //fn_haar = "/usr/share/opencv/haarcascades/haarcascade_frontalface_alt. xml"; // change fn_harr to be quicker LBP (see article) fn_haar = "/usr/share/opencv/haarcascades/lbpcascade_frontalface.xml";

DEBUG cout