| 586 | } |
| 587 | |
| 588 | void* getFrameFromDir(void *i) { |
| 589 | int global_counter = 1; |
| 590 | int frame_counter = 0; |
| 591 | cv::Mat image_uchar; |
| 592 | cv::Mat image_uchar_orig; |
| 593 | cv::Mat image_uchar_prev; |
| 594 | while(1) { |
| 595 | // If the queue is too long, wait for a bit |
| 596 | std::unique_lock<std::mutex> lk(global.get_frames_mutex); |
| 597 | global.get_frames_cond.wait(lk, [](){return |
| 598 | global.input_queue.size() < _max_size_input_queue;}); |
| 599 | if (global.quit_threads or !ros::ok()) break; |
| 600 | // Keep a count of how many frames we've seen in the video |
| 601 | frame_counter++; |
| 602 | |
| 603 | // This should probably be protected. |
| 604 | global.uistate.current_frame = frame_counter-1; |
| 605 | |
| 606 | std::string filename = global.image_list[global.uistate.current_frame]; |
| 607 | image_uchar_orig = cv::imread(filename.c_str(), CV_LOAD_IMAGE_COLOR); |
| 608 | double scale = 0; |
| 609 | if (image_uchar_orig.cols/(double)image_uchar_orig.rows> |
| 610 | DISPLAY_RESOLUTION_WIDTH/(double)DISPLAY_RESOLUTION_HEIGHT) { |
| 611 | scale = DISPLAY_RESOLUTION_WIDTH/(double)image_uchar_orig.cols; |
| 612 | } else { |
| 613 | scale = DISPLAY_RESOLUTION_HEIGHT/(double)image_uchar_orig.rows; |
| 614 | } |
| 615 | cv::Mat M = cv::Mat::eye(2,3,CV_64F); |
| 616 | M.at<double>(0,0) = scale; |
| 617 | M.at<double>(1,1) = scale; |
| 618 | cv::warpAffine(image_uchar_orig, image_uchar, M, |
| 619 | cv::Size(DISPLAY_RESOLUTION_WIDTH, |
| 620 | DISPLAY_RESOLUTION_HEIGHT), |
| 621 | CV_INTER_CUBIC, |
| 622 | cv::BORDER_CONSTANT, cv::Scalar(0,0,0)); |
| 623 | // resize(image_uchar, image_uchar, cv::Size(new_width, new_height), 0, 0, |
| 624 | // CV_INTER_CUBIC); |
| 625 | image_uchar_prev = image_uchar; |
| 626 | |
| 627 | if ( image_uchar.empty() ) continue; |
| 628 | |
| 629 | Frame frame; |
| 630 | frame.ori_width = image_uchar_orig.cols; |
| 631 | frame.ori_height = image_uchar_orig.rows; |
| 632 | frame.index = global_counter++; |
| 633 | frame.video_frame_number = global.uistate.current_frame; |
| 634 | frame.data_for_wrap = new unsigned char [DISPLAY_RESOLUTION_HEIGHT |
| 635 | * DISPLAY_RESOLUTION_WIDTH * 3]; //fill after process |
| 636 | frame.data_for_mat = new float [DISPLAY_RESOLUTION_HEIGHT |
| 637 | * DISPLAY_RESOLUTION_WIDTH * 3]; |
| 638 | process_and_pad_image(frame.data_for_mat, image_uchar, |
| 639 | DISPLAY_RESOLUTION_WIDTH, DISPLAY_RESOLUTION_HEIGHT, |
| 640 | 0); |
| 641 | |
| 642 | frame.scale = scale; |
| 643 | //pad and transform to float |
| 644 | int offset = 3 * NET_RESOLUTION_HEIGHT * NET_RESOLUTION_WIDTH; |
| 645 | frame.data = new float [BATCH_SIZE * offset]; |
no test coverage detected