| 685 | } |
| 686 | |
| 687 | void* getFrameFromCam(void *i) |
| 688 | { |
| 689 | cv::VideoCapture cap; |
| 690 | double target_frame_time = 0; |
| 691 | double target_frame_rate = 0; |
| 692 | if (!_image_dir.empty()) { |
| 693 | return getFrameFromDir(i); |
| 694 | } |
| 695 | |
| 696 | if (_video.empty()) { |
| 697 | CHECK(cap.open(_camera_index)) << "Couldn't open camera " << _camera_index; |
| 698 | cap.set(CV_CAP_PROP_FRAME_WIDTH,CAMERA_FRAME_WIDTH); |
| 699 | cap.set(CV_CAP_PROP_FRAME_HEIGHT,CAMERA_FRAME_HEIGHT); |
| 700 | } else { |
| 701 | CHECK(cap.open(_video)) << "Couldn't open video file " << _video; |
| 702 | target_frame_rate = cap.get(CV_CAP_PROP_FPS); |
| 703 | target_frame_time = 1.0/target_frame_rate; |
| 704 | if (_start_frame) { |
| 705 | cap.set(CV_CAP_PROP_POS_FRAMES, _start_frame); |
| 706 | } |
| 707 | } |
| 708 | |
| 709 | int global_counter = 1; |
| 710 | int frame_counter = 0; |
| 711 | cv::Mat image_uchar; |
| 712 | cv::Mat image_uchar_orig; |
| 713 | cv::Mat image_uchar_prev; |
| 714 | double last_frame_time = -1; |
| 715 | while(1) { |
| 716 | if (global.quit_threads or !ros::ok()) { |
| 717 | break; |
| 718 | } |
| 719 | if (!_video.empty() && _no_frame_drops) { |
| 720 | // If the queue is too long, wait for a bit |
| 721 | if (global.input_queue.size()>10) { |
| 722 | usleep(10*1000.0); |
| 723 | continue; |
| 724 | } |
| 725 | } |
| 726 | cap >> image_uchar_orig; |
| 727 | // Keep a count of how many frames we've seen in the video |
| 728 | if (!_video.empty()) { |
| 729 | if (global.uistate.seek_to_frame!=-1) { |
| 730 | cap.set(CV_CAP_PROP_POS_FRAMES, global.uistate.current_frame); |
| 731 | global.uistate.seek_to_frame = -1; |
| 732 | } |
| 733 | frame_counter = cap.get(CV_CAP_PROP_POS_FRAMES); |
| 734 | |
| 735 | VLOG(3) << "Frame: " << frame_counter << " / " << |
| 736 | cap.get(CV_CAP_PROP_FRAME_COUNT); |
| 737 | // This should probably be protected. |
| 738 | global.uistate.current_frame = frame_counter-1; |
| 739 | if (global.uistate.is_video_paused) { |
| 740 | cap.set(CV_CAP_PROP_POS_FRAMES, frame_counter-1); |
| 741 | frame_counter -= 1; |
| 742 | } |
| 743 | |
| 744 | // Sleep to get the right frame rate. |
no test coverage detected