int main(int argc, char **argv) { ros::init(argc, argv, "n1"); ros::NodeHandle n; message_filters::Subscriber<sensor_msgs::Image> sub_image(n, "camera/rgb/image_color", 1); message_filters::Subscriber<sensor_msgs::Image> sub_disp(n, "/camera/depth_registered/image_raw", 1); // ApproximateTime takes a queue size as its constructor argument, hence MySyncPolicy(10) typedef message_filters::sync_policies::ApproximateTime<sensor_msgs::Image, sensor_msgs::Image> MySyncPolicy; message_filters::Synchronizer<MySyncPolicy> sync(MySyncPolicy(10), sub_image, sub_disp); sync.registerCallback(boost::bind(&callback, _1, _2)); //subscribes to the Kinect video frames ros::Subscriber calibration = n.subscribe("/camera/rgb/camera_info", 1, getCalibration); ros::spin(); return 0; }
main () { int i,j,k; for (i=0; i < PICTURE_VERTICAL_SIZE; i++) { for (j=PICTURE_HORIZONTAL_OFFSET; j < PICTURE_HORIZONTAL_SIZE+PICTURE_HORIZONTAL_OFFSET; j++) { image_original[i][j-PICTURE_HORIZONTAL_OFFSET] = Y_test[i][j]; } } for (i=0; i < PICTURE_VERTICAL_SIZE; i++) { for (j=PICTURE_HORIZONTAL_OFFSET; j < PICTURE_HORIZONTAL_SIZE+PICTURE_HORIZONTAL_OFFSET; j++) { image_test[i][j-PICTURE_HORIZONTAL_OFFSET] = Y_test[i][j]; } } for (i=0; i < PICTURE_VERTICAL_SIZE; i++) { for (j=PICTURE_HORIZONTAL_OFFSET; j < PICTURE_HORIZONTAL_SIZE+PICTURE_HORIZONTAL_OFFSET; j++) { image_back[i][j-PICTURE_HORIZONTAL_OFFSET] = Y_back[i][j]; } } printf("Starting Motion Detection Application: \n\n"); printf("__attribute__((section(\".heapl2ram\"))) pixel Y_back[%d][%d] = \n{\n",PICTURE_VERTICAL_SIZE,PICTURE_HORIZONTAL_SIZE); print_image_vect((pixel*)image_back); printf("};\n"); printf("__attribute__((section(\".heapl2ram\"))) pixel Y_test[%d][%d] = \n{\n",PICTURE_VERTICAL_SIZE,PICTURE_HORIZONTAL_SIZE); print_image_vect((pixel*)image_test); printf("};\n"); printf("Subtraction and binarization treshold \n\n"); sub_image((pixel*)image_test, (pixel*)image_back); print_image((pixel*)image_test); max_pixel= max_image((pixel*)image_test); printf("Max pixel = %d \n\n",max_pixel); printf("Binarization \n\n"); binarisation((pixel*)image_test, (int)max_pixel*3/10,1,0); print_image((pixel*)image_test); printf("Erosion \n\n"); erosion((pixel*)image_test,KERNEL_SIZE,(pixel*)image_back); print_image((pixel*)image_back); printf("Dilatation \n\n"); dilatation((pixel*)image_back,KERNEL_SIZE ,(pixel*)image_test_out); print_image((pixel*)image_test_out); printf("Sobel Horizontal \n\n"); convolution_rect((pixel*)image_test_out, KERNEL_SIZE, sobel1,(pixel*)image_test); val_abs((pixel*)image_test); print_image((pixel*)image_test); printf("Sobel Vertical \n\n"); convolution_rect( (pixel*)image_test_out, KERNEL_SIZE, sobel2,(pixel*)image_back); val_abs((pixel*)image_back); print_image((pixel*)image_back); printf("Final Sum \n\n"); sum_image((pixel*)image_test, (pixel*)image_back); binarisation((pixel*)image_test, 1,0,1); print_image((pixel*)image_test); printf("Final Multiplication \n\n"); multiply((pixel*)image_test, (pixel*)image_original); printf("__attribute__((section(\".heapl2ram\"))) pixel Y_golden[%d][%d] = \n{\n",PICTURE_VERTICAL_SIZE,PICTURE_HORIZONTAL_SIZE); print_image_vect((pixel*)image_test); printf("};\n\n"); printf("Motion Detection Application Completed\n"); }
int main(int argc, char** argv) { bool video_flag = false; std::string video_path; bool dir_flag = false; std::string dir_path; bool output_flag = false; std::string output_path; for (int i = 1; i < argc; ++i) { std::string arg = argv[i]; if (arg == "-f") { video_flag = true; if (++i == argc || strlen(argv[i]) <= 0) { print_missing_option(argv[0], arg); return 1; } video_path = std::string(argv[i]); } else if (arg == "-d") { dir_flag = true; if (++i == argc || strlen(argv[i]) <= 0) { print_missing_option(argv[0], arg); return 1; } dir_path = std::string(argv[i]); } else if (arg == "-o") { output_flag = true; if (++i == argc || strlen(argv[i]) <= 0) { print_missing_option(argv[0], arg); return 1; } output_path = std::string(argv[i]); } else if (arg == "-h" || arg == "--help") { print_usage(argv[0]); return 0; } else { std::cerr << argv[0] << ": invalid argument '" << arg << "'" << std::endl; return 1; } } if (!(video_flag ^ dir_flag)) { std::cerr << argv[0] << ": need to specify either '-f' or '-d' argument, but not both" << std::endl; return 1; } if (!output_flag) { std::cerr << argv[0] << ": missing required argument '-o'" << std::endl; return 1; } cv::VideoCapture cam; std::list<std::string> file_paths; if (video_flag) { cam.open(video_path); } else if (dir_flag) { boost::filesystem::path dir(dir_path); if (! boost::filesystem::exists(dir)) { std::cerr << "'" << dir_path << "' does not exist" << std::endl; return 2; } if (! boost::filesystem::is_directory(dir)) { std::cerr << "'" << dir_path << "' is not a directory" << std::endl; return 2; } boost::filesystem::directory_iterator end_dir_itr; for (boost::filesystem::directory_iterator dir_itr(dir); dir_itr != end_dir_itr; ++dir_itr) { if (boost::filesystem::is_regular_file(dir_itr->status())) { file_paths.push_back(dir_itr->path().generic_string()); } } if (file_paths.empty()) { std::cerr << "'" << dir_path << "' does not contain any files" << std::endl; return 2; } } std::list<std::string>::const_iterator file_itr = file_paths.begin(); size_t sign_index = 0; while (true) { cv::Mat image; if (video_flag) { cam >> image; } else if (dir_flag) { image = cv::imread(*file_itr); } if (! image.data) { std::cerr << "Error reading from device or file." << std::endl; return 1; } while (image.rows > 1000 || image.cols > 1000) { cv::resize(image, image, cv::Size(image.cols / 2, image.rows / 2)); } cv::imshow("Output", image); cv::Mat display_image; image.copyTo(display_image); std::vector<std::vector<cv::Point> > contours = segmentForeground(image); std::vector<cv::Rect> bounding_rects; for (size_t i = 0; i < contours.size(); ++i) { bounding_rects.push_back(scaleRectWithLimits(cv::boundingRect(contours[i]), cv::Point(0,0), cv::Point(image.cols,image.rows), default_scale)); cv::rectangle(display_image, bounding_rects[i], cv::Scalar(0,255,255), 2); } for (size_t i = 0; i < contours.size(); ++i) { // Construct file output path. std::string sub_img_output_path = output_path + "/" + std::to_string(sign_index) + ".jpg"; // Redraw the current rectangle. cv::rectangle(display_image, bounding_rects[i], cv::Scalar(255,0,0), 2); cv::imshow("Output", display_image); // Create a sub image of the area inside the rectangle and display it. cv::Mat sub_image(image, cv::Range(bounding_rects[i].tl().y, bounding_rects[i].br().y), cv::Range(bounding_rects[i].tl().x, bounding_rects[i].br().x)); cv::namedWindow("Sign"); cv::imshow("Sign", sub_image); while (true) { char key = cv::waitKey(); if (key == ESCAPE_KEY) { goto exit_video_loop; } else if (key == 'n') { cv::rectangle(display_image, bounding_rects[i], cv::Scalar(0,0,255), 2); break; } else if (key == 'y') { ++sign_index; if (! cv::imwrite(sub_img_output_path, sub_image)) { std::cerr << "Error writing to file " << sub_img_output_path << std::endl; return 1; } cv::rectangle(display_image, bounding_rects[i], cv::Scalar(0,255,0), 2); break; } else if (key == 's') { goto exit_frame_loop; } } } exit_frame_loop: if (dir_flag) { ++file_itr; if (file_itr == file_paths.end()) { std::cout << "No more images in the directory." << std::endl; break; } } }
int main(int argc, char **argv) { /** * The ros::init() function needs to see argc and argv so that it can perform * any ROS arguments and name remapping that were provided at the command line. For programmatic * remappings you can use a different version of init() which takes remappings * directly, but for most command-line programs, passing argc and argv is the easiest * way to do it. The third argument to init() is the name of the node. * * You must call one of the versions of ros::init() before using any other * part of the ROS system. */ ros::init(argc, argv, "epd4_c1"); /** * NodeHandle is the main access point to communications with the ROS system. * The first NodeHandle constructed will fully initialize this node, and the last * NodeHandle destructed will close down the node. */ ros::NodeHandle n; /** * The subscribe() call is how you tell ROS that you want to receive messages * on a given topic. This invokes a call to the ROS * master node, which keeps a registry of who is publishing and who * is subscribing. Messages are passed to a callback function, here * called chatterCallback. subscribe() returns a Subscriber object that you * must hold on to until you want to unsubscribe. When all copies of the Subscriber * object go out of scope, this callback will automatically be unsubscribed from * this topic. * * The second parameter to the subscribe() function is the size of the message * queue. If messages are arriving faster than they are being processed, this * is the number of messages that will be buffered up before beginning to throw * away the oldest ones. */ message_filters::Subscriber<sensor_msgs::Image> sub_image(n, "/camera/rgb/image_color", 1); message_filters::Subscriber<sensor_msgs::Image> sub_disp(n, "/camera/depth_registered/image_raw", 1); // ApproximateTime takes a queue size as its constructor argument, hence MySyncPolicy(10) typedef message_filters::sync_policies::ApproximateTime<sensor_msgs::Image, sensor_msgs::Image> MySyncPolicy; message_filters::Synchronizer<MySyncPolicy> sync(MySyncPolicy(10), sub_image, sub_disp); sync.registerCallback(boost::bind(&callback, _1, _2)); ros::Subscriber calibration = n.subscribe("/camera/rgb/camera_info", 1, getCalibration); //subscribes to the Kinect video frames /** * ros::spin() will enter a loop, pumping callbacks. With this version, all * callbacks will be called from within this thread (the main one). ros::spin() * will exit when Ctrl-C is pressed, or the node is shutdown by the master. */ ros::spin(); return 0; }
int Preprocessor::montage(){ string src = para.mon_src; string dst = para.mon_dst; string sys_del = para.sys_del; unsigned int serial_beg = para.serial_beg, serial_end = para.serial_end, x_beg = para.x_beg, x_end = para.x_end, y_beg = para.y_beg, y_end = para.y_end, block_width = para.block_width, block_height = para.block_height, serial_bits = para.serial_bits, thread_num = para.thread_num; unsigned int image_depth = para.image_depth; string image_pre = para.mon_in_pre, image_post = para.mon_in_post; string out_pre = para.mon_out_pre, out_post = para.mon_out_post; #pragma omp parallel for num_threads(thread_num) for(int serial_num = int(serial_beg); serial_num <= int(serial_end); ++ serial_num){ stringstream string_buffer; string serial_string(""); cv::Mat out_image, block_image, re_block_image; cout<<serial_num<<": "<<omp_get_thread_num()<<endl; if(image_depth == 16){ out_image = cv::Mat((y_end - y_beg + 1) * block_height, (x_end - x_beg + 1) * block_width, CV_16UC1, cv::Scalar(0, 0, 0)); //cout<<out_image.rows<<" "<<out_image.cols<<" "<<out_image.depth()<<endl; block_image = cv::Mat(block_height, block_width, CV_16UC1, cv::Scalar(0, 0, 0)); re_block_image = cv::Mat(block_height, block_width, CV_16UC1, cv::Scalar(0, 0, 0)); }else{ out_image = cv::Mat((y_end - y_beg + 1) * block_height, (x_end - x_beg + 1) * block_width, CV_8UC1, cv::Scalar(0, 0, 0)); //cout<<out_image.rows<<" "<<out_image.cols<<" "<<out_image.depth()<<endl; block_image = cv::Mat(block_height, block_width, CV_8UC1, cv::Scalar(0, 0, 0)); re_block_image = cv::Mat(block_height, block_width, CV_8UC1, cv::Scalar(0, 0, 0)); } string x_str, y_str, image_str, out_image_name; string_buffer<<setw(serial_bits)<<setfill('0')<<serial_num; string_buffer>>serial_string; string_buffer.clear(); //cout<<serial_string<<endl; for(unsigned int x_in = x_beg; x_in <= x_end; ++ x_in){ for(unsigned int y_in = y_beg; y_in <= y_end; ++ y_in){ string_buffer<<setw(2)<<setfill('0')<<x_in; string_buffer>>x_str; string_buffer.clear(); string_buffer<<setw(2)<<setfill('0')<<y_in; string_buffer>>y_str; string_buffer.clear(); image_str = src + sys_del + serial_string + sys_del +image_pre + serial_string + "_" + x_str + "_" + y_str + image_post; block_image = cv::imread(image_str.c_str(), CV_LOAD_IMAGE_UNCHANGED); if(!block_image.data){ cout<<"----------------------"<<endl; cout<<"Image Loaded Error!"<<endl; cout<<image_str<<endl; cout<<"----------------------"<<endl; if(image_depth == 8){ block_image = cv::Mat::zeros(block_height, block_width, CV_8UC1); }else if(image_depth == 16){ block_image = cv::Mat::zeros(block_height, block_width, CV_16UC1); } } for(int y_block = 0; y_block < block_image.cols; ++ y_block){ block_image.col(y_block).copyTo(re_block_image.col(block_image.cols - y_block - 1)); } cv::Rect sub_roi((x_in - x_beg) * block_width, (y_in - y_beg) * block_height, block_width, block_height); cv::Mat sub_image(out_image, sub_roi); re_block_image.clone().copyTo(sub_image); } } out_image_name = dst + sys_del + out_pre + serial_string + out_post; cout<<out_image_name<<endl; cv::imwrite(out_image_name, out_image); } return 0; }