@@ -161,17 +161,43 @@ class llm_task {
161161 throw std::string (" img size error" );
162162 }
163163 cv::Mat camera_data (mode_config_.img_h , mode_config_.img_w , CV_8UC2, (void *)msg.data ());
164- cv::Mat bgr ;
165- cv::cvtColor (camera_data, bgr , cv::COLOR_YUV2BGR_YUYV );
166- return inference (bgr );
164+ cv::Mat rgb ;
165+ cv::cvtColor (camera_data, rgb , cv::COLOR_YUV2RGB_YUYV );
166+ return inference (rgb, false );
167167 }
168168
169- bool inference (cv::Mat &src)
169+ bool inference_raw_rgb (const std::string &msg)
170+ {
171+ if (inference_mtx_.try_lock ())
172+ std::lock_guard<std::mutex> guard (inference_mtx_, std::adopt_lock);
173+ else
174+ return true ;
175+ if (msg.size () != mode_config_.img_w * mode_config_.img_h * 3 ) {
176+ throw std::string (" img size error" );
177+ }
178+ cv::Mat camera_data (mode_config_.img_h , mode_config_.img_w , CV_8UC3, (void *)msg.data ());
179+ return inference (camera_data, false );
180+ }
181+
182+ bool inference_raw_bgr (const std::string &msg)
183+ {
184+ if (inference_mtx_.try_lock ())
185+ std::lock_guard<std::mutex> guard (inference_mtx_, std::adopt_lock);
186+ else
187+ return true ;
188+ if (msg.size () != mode_config_.img_w * mode_config_.img_h * 3 ) {
189+ throw std::string (" img size error" );
190+ }
191+ cv::Mat camera_data (mode_config_.img_h , mode_config_.img_w , CV_8UC3, (void *)msg.data ());
192+ return inference (camera_data);
193+ }
194+
195+ bool inference (cv::Mat &src, bool bgr2rgb = true )
170196 {
171197 try {
172198 int ret = -1 ;
173199 std::vector<uint8_t > image (mode_config_.img_w * mode_config_.img_h * 3 , 0 );
174- common::get_input_data_letterbox (src, image, mode_config_.img_w , mode_config_.img_h , true );
200+ common::get_input_data_letterbox (src, image, mode_config_.img_w , mode_config_.img_h , bgr2rgb );
175201 yolo_->SetInput ((void *)image.data (), 0 );
176202 if (0 != yolo_->RunSync ()) {
177203 SLOGE (" Run yolo model failed!\n " );
0 commit comments