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
C++ OpenCV重新映射参数及其使用方法?;_C++_Opencv_Image Processing_Ubuntu 14.04_Remap - Fatal编程技术网

C++ OpenCV重新映射参数及其使用方法?;

C++ OpenCV重新映射参数及其使用方法?;,c++,opencv,image-processing,ubuntu-14.04,remap,C++,Opencv,Image Processing,Ubuntu 14.04,Remap,我不熟悉opencv,但我需要使用函数“重新映射”来校正图像。 我有一个960x1280的图像,和一个9.8MB的名为“remap.bin”的重映射文件(相当于960x1280x4x2,这意味着两个浮动在一个位置(x,y)) Applies a generic geometrical transformation to an image. C++: void remap(InputArray src, OutputArray dst, InputArray map1, InputArray m

我不熟悉opencv,但我需要使用函数“重新映射”来校正图像。 我有一个960x1280的图像,和一个9.8MB的名为“remap.bin”的重映射文件(相当于960x1280x4x2,这意味着两个浮动在一个位置(x,y))

Applies a generic geometrical transformation to an image.

C++: void remap(InputArray src, OutputArray dst, InputArray map1, InputArray map2, int interpolation, int borderMode=BORDER_CONSTANT, const Scalar& borderValue=Scalar())

map1 – The first map of either (x,y) points or just x values having the type CV_16SC2 , CV_32FC1 , or CV_32FC2 . See convertMaps() for details on converting a floating point representation to fixed-point for speed.
map2 – The second map of y values having the type CV_16UC1 , CV_32FC1 , or none (empty map if map1 is (x,y) points), respectively.
根据解释, 我的代码如下:

int main(int argc, char* argv[]){
    if(argc != 3){
        printf("Please enter one path of image and one path of mapdata!\n");
        return 0;
    }
    std::string image_path = argv[1];
    char* remap_path = argv[2];

    cv::Mat src = cv::imread(image_path); 
    cv::Mat dst;
    dst.create( src.size(), src.type());

    cv::Mat map2;
    map2.create( src.size(), CV_32FC1);
    map2.data = NULL;

    cv::Mat mapXY;
    mapXY.create( src.rows, src.cols, CV_64FC1);

    FILE *fp;
    fp = fopen(remap_path, "rb");
    fread(mapXY.data, sizeof(float), mapXY.cols*mapXY.rows*2, fp);
    fclose(fp);


    imshow("src", src);
    printf("remap!\n");
    cv::remap(src, dst, mapXY, map2, cv::INTER_LINEAR);
    imshow("dst", dst);

    cv::waitKey(0);
    return 0;
但当我运行该程序时,我得到以下错误:

OpenCV错误:重新映射文件/home/liliming/OpenCV-2.4.13/modules/imgproc/src/imgwarp.cpp中的断言失败(((map1.type()==cv32fc2 | map1.type()==cv32fc1&&map2.type()=cv32fc1 | map1.type()=cv32fc1))和&!map2.type()=CV.13/modules/imgproc/src/imgwarp,在抛出“CV::Exception”实例后终止调用第3262行:/home/liliming/opencv-2.4.13/modules/imgproc/src/imgwarp.cpp:3262:错误:(-215)((map1.type()=cv32fc2||map1.type()=CV|u 16SC2)和&!map2.data)|(map1.type()=cv32fc1和&map2.type()=CV||32FC1)函数重新映射中止(内核转储)

我对此一无所知。 有人能帮我吗?或者给我一些示例代码
非常感谢!

我将重新映射表分为两个表remapX,remapY。 像这样:

float *data_xy = (float *)malloc(sizeof(float)*960*1280*2);

FILE *fp;
fp = fopen(remap_path, "rb");
fread(data_xy, sizeof(float), 960*1280*2, fp);
fclose(fp);

for(int y=0; y<1280; ++y){
    for(int x=0; x<960; ++x){
        map_x.at<float>(y, x) = data_xy[(y*960+x)*2];
        map_y.at<float>(y, x) = data_xy[(y*960+x)*2+1];
    }
}
它工作得很好。
但是我不知道如何使用一个参数map1来完成重新映射。

OpenCV 3.1的文档说明:

map1    The first map of either (x,y) points or just x values having the type 
CV_16SC2 , CV_32FC1, or CV_32FC2.
断言说map1没有
CV_32FC2
这是因为您正在使用
CV\u 64FC1
类型创建和读取它

您需要将其转换为正确的类型:类型为
CV_32FC2
的二维数组(每个元素两个32位浮点)

文件接着说:

See `convertMaps` for details on converting a 
floating point representation to fixed-point for speed.

可以在此处找到文档:

您可以看到,谢谢,我可以使用带有两个参数(mapX和mapY)的重新映射,但我不知道如何使用带有一个参数(mapXY)的重新映射。
See `convertMaps` for details on converting a 
floating point representation to fixed-point for speed.