繁体   English   中英

使用带有float *的openCV重映射

[英]Using openCV remap with float*

我目前正在从事一个涉及运动补偿的项目。

这时我在cv :: Mat输入中有输入图像;

cv::resize( input, input_resized, cvSize(64,48), 12, 12, CV_INTER_AREA);
input_resized.convertTo(input_float, CV_32F); //this might be redundant while cv::rezise dst should be 32F.

现在,运动矢量存储在2通道cv :: Mat运动中,其存储方式如下:

// w -image.width , h-image.height
    X0  Y0  X1   Y1   X2   Y2   ...  Xw-1  Yw-1      
    Xw  Yw  Xw+1 Yw+1 Xw+2 Yw+2 ...  X2w-1 Y2w-1
    ...
    X(h-1)w Y(h-1)w   ............. X(h-1)(w-1)Y(h-1)(w-1)

所以,如果我使用:

std::vector<cv::Mat> motionvect(2);
cv::split(motion, motionvect);

我将在motionvect(0)中获得X,在motionvect2(1)中获得Y。

此外,我尝试了:

std::vector<cv::Mat> rgbChannels(3);
cv::split(input_float, rgbChannels);
cv::remap(rgbChannels[0], outChannels[0], motionvect[0], motionvect[1], CV_INTER_LINEAR, IPL_BORDER_CONSTANT, cvScalar(0,0, 0));
cv::remap(rgbChannels[1], outChannels[1], motionvect[0], motionvect[1], CV_INTER_LINEAR, IPL_BORDER_CONSTANT, cvScalar(0,0, 0));
cv::remap(rgbChannels[2], outChannels[2], motionvect[0], motionvect[1], CV_INTER_LINEAR, IPL_BORDER_CONSTANT, cvScalar(0,0, 0));

cv::merge(outChannels, input_with_motion);

我得到的结果非常奇怪,有人告诉我这是因为Y向量。 显然,如果X像这样:

1  2  3  4  5
6  7  8  9  10
11 12 13 14 15

那么Y应该是:

1  6  11  
2  7  12  
3  8  13
4  9  14
5  10 15

那是对的吗? 转置矩阵的排序。 如果是真的,是否有任何函数可以将motiovect [2]更改为以下形式,还是应该对每个单独的组件进行更改?

另外,对于最后一步,我需要在过程中的其他时间应用重新映射。 像这样:

Function1 ( (float*) input_float.data , (float*) motion.data, (unsigned char*) out.data );
   Function2 ( float* input, float* R, float* G, float* B);
   Function3 ( float* R, float* G, float* B, float* W, float* Z);

其中R,G,B,W,Z为float *类型,并分配有

 R = (float*) malloc (frame_size * sizeof(float) );

我需要对float * A和float * B应用运动补偿,但是不允许这些输入重新映射。 它们必须是InputArray,我找不到任何将float *转换为任何可接受的InputArray类型的方法。

我知道我思想上不太有条理,但希望您能至少理解我的一个问题。 1.如果我将运动矢量存储在x0 y0 x1 y1 ..这样的cv :: Mat中,该如何应用重映射? 2.我可以将float *转换为cv :: remap的可接受输入吗?

我发现本教程http://docs.opencv.org/doc/tutorials/imgproc/imgtrans/remap/remap.html对于理解如何设置map1,map2参数非常有用。 最后是这样的:

for(int i=0; i< rows; i++){
        for(int j=0; j<col; j++)
            { 
             map_x.at<float>(i,j) = j + motion_vect.ptr<float>(i)[2*j+0];
             map_y.at<float>(i,j) = i + motion_vect.ptr<float>(i)[2*j+1];;
        }}

要将输出图像作为原始图像:

map_x.at<float>(i,j) = j ;
map_y.at<float>(i,j) = i ;

对于您的#2,您可以执行以下操作以将浮点值从指针放入某些Mat中:

cv::Mat testMat = cv::Mat::zeros(2, 3, CV_32F);
std::cout << "(1, 2) elem = " << testMat.at<float>(1, 2) << std::endl;

float* pTestVal = new float;
*pTestVal = 3.14F;
testMat.at<float>(1, 2) = *pTestVal;
delete pTestVal;

std::cout << "(1, 2) elem = " << testMat.at<float>(1, 2) << std::endl;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM