Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在设计时图像类型未知时,如何访问cv::mat中的数据?_C++_Opencv - Fatal编程技术网

C++ 在设计时图像类型未知时,如何访问cv::mat中的数据?

C++ 在设计时图像类型未知时,如何访问cv::mat中的数据?,c++,opencv,C++,Opencv,我有一组输入图像和一个输出图像,我需要组合输入图像并创建输出图像 我有以下代码: for (int j = 0; j < Height; ++j) { for (int i = 0; i < Width; ++i) { int xx,yy,Id; algo.calXY(i, j, xx, yy,Id); cv::Vec3b value=cubeImage.images[Id].at<cv::Vec3b>(yy

我有一组输入图像和一个输出图像,我需要组合输入图像并创建输出图像

我有以下代码:

for (int j = 0; j < Height; ++j)
{
    for (int i = 0; i < Width; ++i)
    {
        int xx,yy,Id;
        algo.calXY(i, j, xx, yy,Id);
        cv::Vec3b value=cubeImage.images[Id].at<cv::Vec3b>(yy,xx);
         output.at<cv::Vec3b>(j,i)=value;
    }
 }
for(int j=0;j
此代码仅在输入图像为不带alpha通道的RGB时有效

如何将其更改为,以便在输入图像为ARGB时正常工作


我试图将
cv::Vec3b
替换为
cv::Vec,
,但它没有编译,因为它需要一个编译时变量作为类型。

您可以通过一次复制一个通道来实现这一点:

for (int j = 0; j < Height; ++j)
{
    uchar* orow = output.ptr<uchar>(j);

    for (int i = 0; i < Width; ++i)
    {
        int xx, yy, Id;
        algo.calXY(i, j, xx, yy, Id);  

        //cv::Vec3b value=cubeImage.images[Id].at<cv::Vec3b>(yy,xx);   
        uchar* mrow = cubeImage.images[Id].ptr<uchar>(yy);

        mrow += xx * output.channels(); 

        // output.at<cv::Vec3b>(j,i)=value;
        for(int c = 0; c < output.channels(); ++ c)
            *orow++ = *mrow++;
    }
}
for(int j=0;j
开关(材料通道){情况1:…;情况3:…情况4:…}