# vyuy\_remap/app.cpp /******************************************************************************* Copyright (c) 2021 Qualcomm Technologies, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted (subject to the limitations in the disclaimer below) provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Qualcomm Technologies, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. @brief Program to run FastADAS VYUY remap pipeline(s). *******************************************************************************/ #include #include #include #include #include "util.h" #ifdef USE_OPENCV #include #include #include #include #endif #define NORMALIZE 1 #define ST // single- or multi-threaded versions int main( int argc, char** argv ) { int retVal = 0; FadasError_e status = FADAS_ERROR_NONE; if( FADAS_ERROR_NONE != FadasInit( nullptr ) ) { UTIL_ERROR( "FadasInit failed (status = %u)", status ); return -1; } // Input VYUY image const size_t balign = 128; const char* vyuy_path = "img4_2688x1520.vyuy"; uint32_t vyuy_w = 2688; uint32_t vyuy_h = 1520; uint32_t vyuy_s = 2 * vyuy_w; FadasImage_t vyuyImg = { 0 }; if( FadasCreateImage( FADAS_BUF_TYPE_IN, vyuy_w, vyuy_h, FADAS_IMAGE_FORMAT_VYUY, &vyuyImg, balign ) != FADAS_ERROR_NONE ) { UTIL_ERROR( "FadasCreateImage failed" ); FadasDeInit(); return -1; } UTIL_ReadRAW( vyuy_path, vyuy_s, vyuyImg.props.height, vyuyImg.props.stride[0], vyuyImg.plane[0] ); FadasImage_t outImg = { 0 }; #if 0 // full image FadasRemapMap_t* map = FadasRemap_CreateMapNoUndistortion( vyuy_w, vyuy_h, vyuy_w, vyuy_h, FADAS_REMAP_PIPELINE_VYUY_TO_RGB888, 0 ); if( nullptr == map ) { UTIL_ERROR( "Failed to create map!\n" ); FadasDestroyImage(&vyuyImg); FadasDeInit(); return -1; } FadasROI_t roi = { 0 }; // Set ROI to entire image float32_t roi_scl = 1.0; if( FADAS_ERROR_NONE != FadasCreateImage( FADAS_BUF_TYPE_INOUT, vyuyImg.props.width, vyuyImg.props.height, FADAS_IMAGE_FORMAT_RGB888, &outImg, balign ) ) { UTIL_ERROR( "FadasCreateImage failed" ); FadasRemap_DestroyMap(map); FadasDestroyImage(&vyuyImg); FadasDeInit(); return -1; } #else // ROI FadasRemapMap_t* map = FadasRemap_CreateMapNoUndistortion( vyuy_w, vyuy_h, vyuy_w, vyuy_h, FADAS_REMAP_PIPELINE_VYUY_TO_RGB888_ROISCALE, 0 ); if( nullptr == map ) { UTIL_ERROR( "Failed to create map!\n" ); FadasDestroyImage( &vyuyImg ); FadasDeInit(); return -1; } // Set ROI to quarter image, center ROI, and scale out to right/bottom corner const uint32_t out_scl = 2; FadasROI_t roi = { vyuyImg.props.width / 4, vyuyImg.props.height / 4, vyuyImg.props.width / out_scl, vyuyImg.props.height / out_scl }; float32_t roi_scl = 1.5; if( FADAS_ERROR_NONE != FadasCreateImage( FADAS_BUF_TYPE_INOUT, vyuyImg.props.width / out_scl, vyuyImg.props.height / out_scl, FADAS_IMAGE_FORMAT_RGB888, &outImg, balign ) ) { UTIL_ERROR( "FadasCreateImage failed" ); FadasRemap_DestroyMap(map); FadasDestroyImage(&vyuyImg); FadasDeInit(); return -1; } #endif #ifdef ST if( FADAS_ERROR_NONE != FadasRemap_Run( map, &vyuyImg, &outImg, &roi, roi_scl) ) { UTIL_ERROR( "FadasRemap_Run failed" ); retVal = -1; } #else int32_t n_threads_affinity[] = { 0,1,2,3 }; void* wrkrs = FadasRemap_CreateWorkers( 4, n_threads_affinity, FADAS_REMAP_PIPELINE_VYUY_TO_RGB888_ROISCALE ); if( nullptr == wrkrs) { UTIL_ERROR( "creating wrkrs" ); retVal = -1; } else { if( FADAS_ERROR_NONE != FadasRemap_RunMT( wrkrs, map, &vyuyImg, &outImg, &roi, roi_scl ) ) { UTIL_ERROR( "FadasRemap_Run MT failed" ); retVal = -1; } if( FADAS_ERROR_NONE != FadasRemap_DestroyWorkers( wrkrs ) ) { UTIL_ERROR( "FadasRemap_DestroyWorkers failed" ); retVal = -1; } } #endif if( 0 == retVal ) { UTIL_WritePPM( "tmp_img4_2688x1520.ppm", outImg.props.width, outImg.props.height, 255, (uint8_t*)outImg.plane[0], outImg.props.stride[0] ); } #ifdef USE_OPENCV cv::Mat img_ocv0( outImg.props.height, outImg.props.width, CV_8UC3, outImg.plane[0], outImg.props.stride[0] ); cv::Mat img_display0( outImg.props.height, outImg.props.width, CV_8UC3 ); cv::cvtColor( img_ocv0, img_display0, cv::COLOR_RGB2BGR ); cv::namedWindow( "outImg", cv::WINDOW_AUTOSIZE ); cv::imshow( "outImg", img_display0 ); cv::waitKey( 0 ); #endif FadasDestroyImage( &vyuyImg ); FadasDestroyImage( &outImg ); FadasRemap_DestroyMap( map ); FadasDeInit(); return retVal; } Copy to clipboard Last Published: Sep 30, 2024 [Previous Topic uyvy\_remap/app.cpp](https://docs.qualcomm.com/bundle/publicresource/80-63309-1/topics/uyvy-remap.md) [Next Topic svd/app.cpp](https://docs.qualcomm.com/bundle/publicresource/80-63309-1/topics/svd.md)