c++ - 将 openCV 重映射与 float* 结合使用

标签 c++ opencv rgb motion remap

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

此时我在 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.

现在运动 vector 存储在一个 2 channel 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 vector 。 显然如果 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

这样对吗?一种转置矩阵。如果是这样,是否有任何函数可以将 motiovec[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. 如果我将运动 vector 存储在 cv::Mat 中,如 x0 y0 x1 y1 ..,如何应用重映射? 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 ;

关于c++ - 将 openCV 重映射与 float* 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20387402/

相关文章:

c++ - 不间断执行 Cpp Linux 代码

c++ - 使用带有 SURF 的 SVM 时出错

java - ImageJ API : Getting RGB values from image

PHP:如何将 "near white"表示为颜色?

c++ - 通过动态规划平衡排序括号

c++ - 将包含十六进制值的字符串转换为c中的字符字节

c++ - 无法初始化类成员?

c++ - 使用 OpenCV 从图像中去除水印

python - 需要通过OpenCV Python检测书籍

java - RGB转CMYK及反向算法