2017-01-20 5 views
0

opencv에 익숙하지 않지만 'remap'기능을 사용하여 이미지를 수정해야합니다. 따르면OpenCV 매개 변수를 다시 매핑하고 사용하는 방법

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. 

; I는 960x1280 갖는 화상 및 9.8MB (한 위치 (x, y)에있는 두 개의 플로트를 의미 960x1280x4x2으로 같게된다)와 'remap.bin'라는 리맵 파일이 에 대한 설명, I의이 같은 코드 :

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 Error: Assertion failed (((map1.type() == CV_32FC2 || map1.type() == CV_16SC2) && !map2.data) || (map1.type() == CV_32FC1 && map2.type() == CV_32FC1)) in remap, file /home/liliming/opencv-2.4.13/modules/imgproc/src/imgwarp.cpp, line 3262 terminate called after throwing an instance of 'cv::Exception' what(): /home/liliming/opencv-2.4.13/modules/imgproc/src/imgwarp.cpp:3262: error: (-215) ((map1.type() == CV_32FC2 || map1.type() == CV_16SC2) && !map2.data) || (map1.type() == CV_32FC1 && map2.type() == CV_32FC1) in function remap Aborted (core dumped)

을 내가 그것에 대해 아무 생각이 없습니다. 도와 주시겠습니까? 아니면 샘플 코드를 제공 할 수 있습니까? 대단히 감사합니다.

+0

당신은 [이 답변을] 볼 수 있습니다 (http://stackoverflow.com/questions/10364201/image-transformation-in-opencv) –

+0

고마워, 나는 두 개의 매개 변수 (mapX 및 mapY)를 사용하는 방법을 모르지만 하나의 매개 변수 (mapXY)로지도. –

답변

0

remap 테이블을 두 개의 테이블 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]; 
    } 
} 

그리고 그것은 잘 작동

cv::remap(src, dst, map_x, map_y, cv::INTER_LINEAR); 

사용합니다. 그러나 매핑을 완료하는 데 하나의 매개 변수 map1을 사용하는 방법을 모르겠습니다.

0

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_64FC1의 유형을 읽고 있기 때문입니다 CV_32FC2 의 유형을하지 않는 것을 말한다.

당신은 올바른 유형으로 변환해야합니다 형식 CV_32FV2의 두 가지 차원의 배열

문서는 계속 말을 (요소마다 두 개의 32 비트 수레.) :

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

문서 여기에서 찾을 수 있습니다 : https://docs.opencv.org/3.1.0/da/d54/group__imgproc__transform.html#gab75ef31ce5cdfb5c44b6da5f3b908ea4