Ask Your Question
0

Image trasformation - cylindrical

asked 2014-09-07 09:34:38 -0600

Phalaen gravatar image

Hi, I am trying to apply the code reported here: http://stackoverflow.com/questions/12017790/warp-image-to-appear-in-cylindrical-projection I have modified it, the program runs but there are no changes in the final image.. I cannot find the error, any suggestion? Thank you, Phalaen

// Progetto.cpp : Defines the entry point for the console application.

//

include "stdafx.h"

include <opencv2 core="" core.hpp="">

include <opencv2 imgproc="" imgproc.hpp="">

include <opencv2 highgui="" highgui.hpp="">

include <iostream>

include <cstdlib>

include <fstream>

include <stdio.h>

include <stdlib.h>

include <string.h>

include <iomanip>

using namespace cv; using namespace std;

cv::Point2f convert_pt(cv::Point2f point,float w,float h) { //center the point at 0,0 cv::Point2f pc(point.x-w/2,point.y-h/2);

//these are your free parameters float f = w/2; float r = w/2;

float omega = w/2; float z0 = w/2;

float zc = (2z0+sqrt(4z0z0-4(pc.xpc.x/(ff)+1)(z0z0-rr)))/(2 (pc.xpc.x/(ff)+1)); cv::Point2f final_point(pc.xzc/f,pc.yzc/f); final_point.x += w/2; final_point.y += h/2; return final_point; }

int main(int argc, char *argv[]) {

if( argc != 2) { cout <<" Usage: display_image ImageToLoadAndDisplay" << endl; return -1; }

Mat image, image2;
image = imread(argv[1], CV_LOAD_IMAGE_COLOR);   // Read the file

if(! image.data )                              // Check for invalid input
{
    cout <<  "Could not open or find the image" << std::endl ;
    return -1;
}

namedWindow( "Prima", WINDOW_AUTOSIZE );// Create a window for display.
imshow( "Prima", image );                   // Show our image inside it.
image2 = image ;

/* for(int y = 0; y < height; y++) { for(int x = 0; x < width; x++) { cv::Point2f current_pos(x,y); final_point = convert_pt(current_pos, width, height);

    cv::Point2i top_left((int)final_point.x,(int)final_point.y); //top left because of integer rounding

    //make sure the point is actually inside the original image
    if(top_left.x < 0 ||
       top_left.x > width-2 ||
       top_left.y < 0 ||
       top_left.y > height-2)
    {
        continue;
    }

    //bilinear interpolation
    float dx = final_point.x-top_left.x;
    float dy = final_point.y-top_left.y;

    float weight_tl = (1.0 - dx) * (1.0 - dy);
    float weight_tr = (dx)       * (1.0 - dy);
    float weight_bl = (1.0 - dx) * (dy);
    float weight_br = (dx)       * (dy);

    uchar value =   weight_tl * image.at<uchar>(top_left) +  weight_tr * image2.at<uchar>(top_left.y,top_left.x+1) + weight_bl * image2.at<uchar>(top_left.y+1,top_left.x) +  weight_br * image2.at<uchar>(top_left.y+1,top_left.x+1);

    dest_im2.at<uchar>(y,x) = value;
}

} */

namedWindow( "Dopo", CV_WINDOW_AUTOSIZE ); imshow( "Dopo", image2 );

waitKey(0); return 0; }

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-09-07 10:10:24 -0600

You only copy your original image to the image2-variable. All your warping-stuff just changes dest_img2. Have you tried to show this image?

edit flag offensive delete link more

Comments

Thank you FooBar, I have tried so: namedWindow( "Dopo", CV_WINDOW_AUTOSIZE ); imshow( "Dopo", dest_im2 );

but there is this error: error C2065: 'dest_im2' : undeclared identifier

How could I solve this problem? Thank you!

Phalaen gravatar imagePhalaen ( 2014-09-12 09:43:23 -0600 )edit

Where do you declare this image?

FooBar gravatar imageFooBar ( 2014-09-13 06:51:56 -0600 )edit

Question Tools

Stats

Asked: 2014-09-07 09:34:38 -0600

Seen: 394 times

Last updated: Sep 07 '14