@@ -357,62 +357,56 @@ void Camera::UpdateState(uint64_t currentSimNanos)
357357 imageBuffer = this ->imageInMsg ();
358358 this ->sensorTimeTag = this ->imageInMsg .timeWritten ();
359359 }
360- /* Added for debugging purposes */
360+
361361 if (!this ->filename .empty ()){
362362 imageCV = imread (this ->filename , cv::IMREAD_COLOR);
363- this ->applyFilters (imageCV, blurred);
364- if (this ->saveImages == 1 ){
365- if (!cv::imwrite (localPath, blurred)) {
366- bskLogger.bskLog (BSK_WARNING, " camera: wasn't able to save the camera module image" );
367- }
368- }
369363 }
370364 else if (imageBuffer.valid == 1 && imageBuffer.timeTag >= currentSimNanos){
371365 /* ! - Recast image pointer to CV type*/
372366 std::vector<unsigned char > vectorBuffer ((char *)imageBuffer.imagePointer ,
373367 (char *)imageBuffer.imagePointer + imageBuffer.imageBufferLength );
374368 imageCV = cv::imdecode (vectorBuffer, cv::IMREAD_COLOR);
375-
376- this ->applyFilters (imageCV, blurred);
377- if (this ->saveImages == 1 ){
378- if (!cv::imwrite (localPath, blurred)) {
379- bskLogger.bskLog (BSK_WARNING, " camera: wasn't able to save the camera module image" );
380- }
381- }
382- /* ! If the permanent image buffer is not populated, it will be equal to null*/
383- if (this ->pointImageOut != nullptr ) {
384- free (this ->pointImageOut );
385- this ->pointImageOut = nullptr ;
386- }
387- /* ! - Encode the cv mat into a png for the future modules to decode it the same way */
388- std::vector<unsigned char > buf;
389- std::vector<int > compression = {cv::IMWRITE_PNG_COMPRESSION, 0 };
390- if (!cv::imencode (" .png" , blurred, buf, compression) || buf.empty ()) {
391- bskLogger.bskLog (BSK_ERROR, " camera: failed to encode image output buffer." );
392- return ;
393- }
394- if (buf.size () > (size_t )std::numeric_limits<int32_t >::max ()) {
395- bskLogger.bskLog (BSK_ERROR, " camera: encoded image output buffer is too large." );
396- return ;
397- }
398- /* ! - Output the saved image */
399- imageOut.valid = 1 ;
400- imageOut.timeTag = imageBuffer.timeTag ;
401- imageOut.cameraID = imageBuffer.cameraID ;
402- imageOut.imageType = imageBuffer.imageType ;
403- imageOut.imageBufferLength = (int32_t )buf.size ();
404- this ->pointImageOut = malloc (imageOut.imageBufferLength *sizeof (char ));
405- if (this ->pointImageOut == nullptr ) {
406- bskLogger.bskLog (BSK_ERROR, " camera: failed to allocate image output buffer." );
407- return ;
408- }
409- memcpy (this ->pointImageOut , buf.data (), imageOut.imageBufferLength *sizeof (char ));
410- imageOut.imagePointer = this ->pointImageOut ;
411-
412- this ->imageOutMsg .write (&imageOut, this ->moduleID , currentSimNanos);
413369 }
414370 else {
415371 /* ! - If no image is present, write zeros in message */
416372 this ->imageOutMsg .write (&imageOut, this ->moduleID , currentSimNanos);
373+ return ;
374+ }
375+ this ->applyFilters (imageCV, blurred);
376+ if (this ->saveImages == 1 ){
377+ if (!cv::imwrite (localPath, blurred)) {
378+ bskLogger.bskLog (BSK_WARNING, " camera: wasn't able to save the camera module image" );
379+ }
380+ }
381+ /* ! If the permanent image buffer is not populated, it will be equal to null*/
382+ if (this ->pointImageOut != nullptr ) {
383+ free (this ->pointImageOut );
384+ this ->pointImageOut = nullptr ;
417385 }
386+ /* ! - Encode the cv mat into a png for the future modules to decode it the same way */
387+ std::vector<unsigned char > buf;
388+ std::vector<int > compression = {cv::IMWRITE_PNG_COMPRESSION, 0 };
389+ if (!cv::imencode (" .png" , blurred, buf, compression) || buf.empty ()) {
390+ bskLogger.bskLog (BSK_ERROR, " camera: failed to encode image output buffer." );
391+ return ;
392+ }
393+ if (buf.size () > (size_t )std::numeric_limits<int32_t >::max ()) {
394+ bskLogger.bskLog (BSK_ERROR, " camera: encoded image output buffer is too large." );
395+ return ;
396+ }
397+ /* ! - Output the saved image */
398+ imageOut.valid = 1 ;
399+ imageOut.timeTag = imageBuffer.timeTag ;
400+ imageOut.cameraID = imageBuffer.cameraID ;
401+ imageOut.imageType = imageBuffer.imageType ;
402+ imageOut.imageBufferLength = (int32_t )buf.size ();
403+ this ->pointImageOut = malloc (imageOut.imageBufferLength *sizeof (char ));
404+ if (this ->pointImageOut == nullptr ) {
405+ bskLogger.bskLog (BSK_ERROR, " camera: failed to allocate image output buffer." );
406+ return ;
407+ }
408+ memcpy (this ->pointImageOut , buf.data (), imageOut.imageBufferLength *sizeof (char ));
409+ imageOut.imagePointer = this ->pointImageOut ;
410+
411+ this ->imageOutMsg .write (&imageOut, this ->moduleID , currentSimNanos);
418412}
0 commit comments