Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <fstream>
- #include <raspicam/raspicam_cv.h>
- #include <opencv2/core/core.hpp>
- #include <opencv2/imgproc/imgproc.hpp>
- #include <opencv2/highgui/highgui.hpp>
- void set_camera_resolution(raspicam::RaspiCam_Cv camera, int width, int height){
- camera.set(CV_CAP_PROP_FRAME_WIDTH, width);
- camera.set(CV_CAP_PROP_FRAME_HEIGHT, height);
- }
- void set_camera_fps(raspicam::RaspiCam_Cv camera, double fps){
- camera.set(CV_CAP_PROP_FPS, fps);
- }
- void record_video(int length, std::string filename){
- }
- void debug(std::string to_print, bool new_line = true){
- if(new_line){
- std::cout << to_print << std::endl;
- }else{
- std::cout << to_print;
- }
- }
- cv::Mat thumbnail(cv::Mat input){
- cv::Size size(100, 75);
- cv::Mat resized;
- cv::resize(input, resized, size, 0, 0, cv::INTER_CUBIC);
- return resized;
- }
- cv::Mat snap_thumbnail(raspicam::RaspiCam_Cv camera){
- cv::Mat image_captured;
- debug("Before grabbing");
- camera.grab();
- debug("After grabbing, before retrieving");
- camera.retrieve(image_captured);
- debug("After retrieving");
- return thumbnail(image_captured);
- }
- void motion_sensing_loop(raspicam::RaspiCam_Cv camera, int threshold_pixel_diff, int threshold_pixel_num){
- cv::Mat image_previous = cv::Mat(snap_thumbnail(camera));
- while(true){
- cv::Mat image_current = cv::Mat(snap_thumbnail(camera));
- uchar pixel_green_previous, pixel_green_current;
- for(int y = 0; y < image_current.rows; y++){
- cv::Vec3b* pixel_row_previous = image_previous.ptr<cv::Vec3b>(y);
- cv::Vec3b* pixel_row_current = image_current.ptr<cv::Vec3b>(y);
- for(int x = 0; x < image_current.cols; x++){
- pixel_green_previous = pixel_row_previous[x][1];
- pixel_green_current = pixel_row_current[x][1];
- std::string pixel_green_previous_string(reinterpret_cast<char*>(pixel_green_previous));
- std::string pixel_green_current_string(reinterpret_cast<char*>(pixel_green_current));
- debug("[", false);
- debug(pixel_green_previous_string, false);
- debug("] - [", false);
- debug(pixel_green_current_string, false);
- debug("]");
- }
- }
- }
- }
- int main(int argc, char **argv){
- if(argc != 2){
- debug("Invalid arguments");
- return 1;
- }
- std::string filename = argv[1];
- debug("Filename: ", false);
- debug(filename);
- raspicam::RaspiCam_Cv camera;
- camera.set(CV_CAP_PROP_FORMAT, CV_8UC3);
- int resolution[] = {2592, 1944};
- debug("Camera properties set");
- bool initialized = camera.open();
- if(!initialized){
- debug("Couldn't initialize camera module");
- return 1;
- }else{
- debug("Initialized camera");
- }
- motion_sensing_loop(camera, 20, 20);
- /*debug("Taking picture");
- cv::Mat image;
- camera.grab();
- camera.retrieve(image);
- cv::Size size(100, 75);
- cv::Mat resized;
- cv::resize(image, image, size, 0, 0, cv::INTER_CUBIC);
- cv::imwrite("test.png", image);
- debug("Picture saved");*/
- camera.release();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement