HI_MPI_VPSS_GetChnFrame()获得的数据进行颜色空间转换问题

static HI_VOID* SAMPLE_IVE_ViToVo(HI_VOID* pArgs)
{
    HI_S32 s32Ret;
    SAMPLE_IVE_BG_MODEL_INFO_S* pstBgModelInfo;
    SAMPLE_IVE_BG_MODEL_S* pstBgModel;
    VIDEO_FRAME_INFO_S stBaseFrmInfo;
    VIDEO_FRAME_INFO_S stExtFrmInfo;
    HI_S32 s32MilliSec = 20000;
    VO_CHN voChn = 0;
    VO_LAYER voLayer = 0;
    VENC_CHN vencChn = 0;
    HI_BOOL bEncode;
    HI_BOOL bVo;
    HI_S32 s32VpssGrp = 0;
    HI_S32 as32VpssChn[] = {VPSS_CHN0, VPSS_CHN1};

    pstBgModelInfo = (SAMPLE_IVE_BG_MODEL_INFO_S*)pArgs;
    pstBgModel = &(pstBgModelInfo->stBgModel);
    bEncode = pstBgModelInfo->bEncode; //0
    bVo = pstBgModelInfo->bVo;  // 1
    

    //tset----
    IVE_DST_IMAGE_S stDstData;
    IVE_SRC_IMAGE_S stSrcData;



    IVE_HANDLE hIveHandle;
    HI_BOOL bInstant = HI_TRUE;
    HI_BOOL bFinish = HI_FALSE;
    HI_BOOL bBlock = HI_TRUE;
    // IVE_SRC_DATA_S stSrcData;
    // IVE_DST_DATA_S stDstData;
    IVE_CSC_CTRL_S stCscCtrl;
    //char* pVBufVirt_Y;
    HI_U8 * pImage = NULL; 
    std::cout << " -11:" << std::endl;

    stCscCtrl.enMode = IVE_CSC_MODE_VIDEO_BT601_YUV2RGB;
    HI_U32 u32Size = 0;
    int frame_idx= 0;
    while (HI_FALSE == s_bStopSignal)
    {
        s32Ret = HI_MPI_VPSS_GetChnFrame(s32VpssGrp, as32VpssChn[1], &stExtFrmInfo, s32MilliSec);
        if(HI_SUCCESS != s32Ret)
        {
            SAMPLE_PRT("Error(%#x),HI_MPI_VPSS_GetChnFrame failed, VPSS_GRP(%d), VPSS_CHN(%d)!\n",
                s32Ret,s32VpssGrp, as32VpssChn[1]);
            continue;
        }
        std::cout << " -22:" << std::endl;

        // s32Ret = HI_MPI_VPSS_GetChnFrame(s32VpssGrp, as32VpssChn[0], &stBaseFrmInfo, s32MilliSec);
        // SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS!=s32Ret, EXT_RELEASE,
        //     "Error(%#x),HI_MPI_VPSS_GetChnFrame failed, VPSS_GRP(%d), VPSS_CHN(%d)!\n",
        //     s32Ret,s32VpssGrp, as32VpssChn[0]);

        stSrcData.enType = IVE_IMAGE_TYPE_YUV420SP;   //广义图像的物理地址数组
        stSrcData.au64PhyAddr[0] = stExtFrmInfo.stVFrame.u64PhyAddr[0];  //0
        stSrcData.au64PhyAddr[1] = stExtFrmInfo.stVFrame.u64PhyAddr[1];  //
        stSrcData.au64VirAddr[0] = stExtFrmInfo.stVFrame.u64VirAddr[0];  //0
        stSrcData.au64VirAddr[1] = stExtFrmInfo.stVFrame.u64VirAddr[1];  //
        stSrcData.au32Stride[0] = stExtFrmInfo.stVFrame.u32Stride[0];  //1920
        stSrcData.au32Stride[1] = stExtFrmInfo.stVFrame.u32Stride[1];  //1920


        stSrcData.u32Width   = stExtFrmInfo.stVFrame.u32Width;//1920
        stSrcData.u32Height  = stExtFrmInfo.stVFrame.u32Height; //1080

        stDstData.enType = IVE_IMAGE_TYPE_U8C3_PACKAGE;
        stDstData.u32Width   = stSrcData.u32Width; //高宽同stSrcData
        stDstData.u32Height  = stSrcData.u32Height;
        std::cout << " -stDstData.u32Width:" <<stDstData.u32Width <<std::endl;
        std::cout << " -stDstData.u32Height:" <<stDstData.u32Height<<std::endl;
        stDstData.au32Stride[0]  = stSrcData.au32Stride[0]*3; //1920 ×3
        stDstData.au32Stride[1]  = stExtFrmInfo.stVFrame.u32Stride[1]*3;
        u32Size = stDstData.au32Stride[0] * stDstData.u32Height;
        s32Ret = HI_MPI_SYS_MmzAlloc_Cached(&stDstData.au64PhyAddr[0], (HI_VOID**)&stDstData.au64VirAddr[0], "User", HI_NULL, u32Size);  //1080×1920×3

        if(HI_SUCCESS != s32Ret)
        {       
                HI_MPI_SYS_MmzFree(stSrcData.au64PhyAddr[0], (HI_VOID**)stSrcData.au64VirAddr[0]);
                printf("HI_MPI_SYS_MmzAlloc_Cached Failed!");
                return NULL;
        }

        memset((HI_VOID**)stDstData.au64VirAddr[0], 0, stDstData.u32Height*stDstData.au32Stride[0]);
        s32Ret = HI_MPI_SYS_MmzFlushCache(stDstData.au64PhyAddr[0], (HI_VOID**)stDstData.au64VirAddr[0], stDstData.u32Height*stDstData.au32Stride[0]);
        if(HI_SUCCESS != s32Ret)
        {       

                HI_MPI_SYS_MmzFree(stDstData.au64PhyAddr[0], (HI_VOID**)stDstData.au64VirAddr[0]);
                return NULL;
        }

        s32Ret = HI_MPI_IVE_CSC(&hIveHandle,&stSrcData,&stDstData,&stCscCtrl,bInstant);
        std::cout << " -33:" << std::endl;

        if(HI_SUCCESS != s32Ret)
        {       
                HI_MPI_SYS_MmzFree(stDstData.au64PhyAddr[0], (HI_VOID**)stDstData.au64VirAddr[0]);
                return NULL;
        }
        // u32Size  HI_MPI_SYS_MmzAlloc_Cached分配内存的时候已经有虚拟地址,不需要Mmap了
        // pImage = (HI_U8*)HI_MPI_SYS_Mmap(stDstData.au64PhyAddr[0], stDstData.u32Height*stDstData.au32Stride[0]*3); //pImage返回是一个空指针, stDstData.au64PhyAddr[0]的值是 71c41000,

        // if (HI_NULL == pImage)
        // {
        //         //mmap error: Input/output error
        //         //HI_MPI_SYS_Mmap fail
        //         printf("HI_MPI_SYS_Mmap fail \n");
        //         //HI_MPI_SYS_Munmap(pImage, stDstData.u32Height*stDstData.au32Stride[0]);
        //         return NULL;
        // }
        std::cout << " -44:" << std::endl;
        cv::Mat rgb_mat(stExtFrmInfo.stVFrame.u32Height, stExtFrmInfo.stVFrame.u32Width, CV_8UC3);
        std::cout << " -55:" << std::endl;
        memcpy(rgb_mat.data, &stDstData.au64VirAddr[0], stExtFrmInfo.stVFrame.u32Width * stExtFrmInfo.stVFrame.u32Height);
        std::cout << " -66:" << std::endl;
        std::string save_name = "./data/dst_save/"+ std::to_string(frame_idx)+".jpg";
        cv::imwrite(save_name, rgb_mat);

        
        // s32Ret = SAMPLE_IVE_BgModelProc(pstBgModelInfo, &stExtFrmInfo,stBaseFrmInfo.stVFrame.u32Width,
        //     stBaseFrmInfo.stVFrame.u32Height);
        // SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS!=s32Ret, BASE_RELEASE,
        //     "Error(%#x),SAMPLE_IVE_BgModelProc failed!\n", s32Ret);

        // //Draw rect
        // s32Ret = SAMPLE_COMM_VGS_FillRect(&stBaseFrmInfo, &pstBgModel->stRegion, 0x0000FF00);
        // SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS!=s32Ret, BASE_RELEASE,
        //     "SAMPLE_COMM_VGS_FillRect failed, Error(%#x)!\n", s32Ret);
        
        //Venc
        frame_idx++;
        if (HI_TRUE == bEncode)
        {
            s32Ret = HI_MPI_VENC_SendFrame(vencChn, &stBaseFrmInfo, s32MilliSec);
            SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS!=s32Ret, BASE_RELEASE,
                "HI_MPI_VENC_SendFrame failed, Error(%#x)!\n", s32Ret);
        }

        //Vo
        if (HI_TRUE == bVo)
        {
            s32Ret = HI_MPI_VO_SendFrame(voLayer, voChn, &stBaseFrmInfo, s32MilliSec);          
            SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS!=s32Ret, BASE_RELEASE,
                "HI_MPI_VO_SendFrame failed, Error(%#x)!\n", s32Ret);
        }

        BASE_RELEASE:
            // s32Ret = HI_MPI_VPSS_ReleaseChnFrame(s32VpssGrp,as32VpssChn[0], &stBaseFrmInfo);
            // if (HI_SUCCESS != s32Ret)
            // {
            //     SAMPLE_PRT("Error(%#x),HI_MPI_VPSS_ReleaseChnFrame failed,Grp(%d) chn(%d)!\n",
            //         s32Ret,s32VpssGrp,as32VpssChn[0]);
            // }
            std::cout << "frame_idx:" <<frame_idx<<std::endl;
            s32Ret = HI_MPI_VPSS_ReleaseChnFrame(s32VpssGrp,as32VpssChn[1], &stExtFrmInfo);
            if (HI_SUCCESS != s32Ret)
            {
                SAMPLE_PRT("Error(%#x),HI_MPI_VPSS_ReleaseChnFrame failed,Grp(%d) chn(%d)!\n",
                    s32Ret,s32VpssGrp,as32VpssChn[1]);
            }

        // EXT_RELEASE:
        //     s32Ret = HI_MPI_VPSS_ReleaseChnFrame(s32VpssGrp,as32VpssChn[1], &stExtFrmInfo);
        //     if (HI_SUCCESS != s32Ret)
        //     {
        //         SAMPLE_PRT("Error(%#x),HI_MPI_VPSS_ReleaseChnFrame failed,Grp(%d) chn(%d)!\n",
        //             s32Ret,s32VpssGrp,as32VpssChn[1]);
        //     }
    }

    return NULL;
}

 

 上述rgb_mat报存的结果如下:

 

我分析是,没有完成颜色空间的转换。上面的是我参考: http://bbs.ebaina.com/forum.php?mod=viewthread&tid=75152&extra=page%3D2%26filter%3Dtypeid%26typeid%3D176 这个前辈的做的,楼主做好,说明应该是这个方法每问题,但是我,哎,求助广大朋友呀。

原文链接:加载失败,请重新获取