33
44OCVCamera::OCVCamera (int width, int height, int fps) :
55 Camera(width, height, fps),
6- size(width, height ),
6+ size(0 , 0 ),
77 cap()
88{
99 CV_BACKEND = cv::CAP_DSHOW;
@@ -15,7 +15,8 @@ OCVCamera::OCVCamera(int width, int height, int fps) :
1515 throw std::runtime_error (" No compatible camera found." );
1616 }
1717 is_valid = true ;
18- cap.set (cv::CAP_PROP_BUFFERSIZE, 1 );
18+
19+ w_scale = (float )width/(float )cam_native_width;
1920}
2021
2122OCVCamera::~OCVCamera ()
@@ -30,8 +31,10 @@ bool OCVCamera::is_camera_available()
3031 cap.open (0 , CV_BACKEND);
3132 available = cap.isOpened ();
3233 if (available)
34+ {
35+ cam_native_width = cap.get (cv::CAP_PROP_FRAME_WIDTH);
3336 cap.release ();
34-
37+ }
3538 return available;
3639}
3740
@@ -53,9 +56,22 @@ void OCVCamera::get_frame(uint8_t* buffer)
5356{
5457 cv::Mat frame;
5558 cap.read (frame);
56- cv::resize (frame, frame, size);
59+ // Scale maintaining aspect ratio. If distorted, the model will get confused.
60+ // TODO: Maybe cropping (width,height) section from the center is better.
61+ // cv::resize(frame, frame, size, w_scale, w_scale);
62+ cv::resize (frame, frame, size, w_scale, w_scale);
5763 cv::flip (frame, frame, 1 );
5864 for (int i = 0 ; i < frame.cols * frame.rows * 3 ; i++)
5965 buffer[i] = frame.data [i];
6066
6167}
68+
69+ void OCVCamera::set_settings (CameraSettings& settings)
70+ {
71+ // TODO
72+ }
73+
74+ CameraSettings OCVCamera::get_settings ()
75+ {
76+ return CameraSettings ();
77+ }
0 commit comments