Sunday, 15 May 2011

c++ - Copying of pixels when rotating a picture 90 degrees [Vec3d vs Vec3b] -



c++ - Copying of pixels when rotating a picture 90 degrees [Vec3d vs Vec3b] -

yes, know there function this, (very simple) function larn opencv basics.

i checked pseudo-code 5 times , pretty sure no logical error.

class="lang-c prettyprint-override">#include <stdio.h> #include <opencv2/core/core.hpp> #include <opencv2/imgproc/imgproc.hpp> #include <opencv2/highgui/highgui.hpp> using namespace cv; int main(int argc, const char *argv[]) { if (argc!=2 || argv[1]=="") { printf("no image specified."); exit(-1); } mat im, out; const string fn = argv[1]; im = cv::imread(fn); out.create(im.cols, im.rows, cv_8uc3); //int tmp = 0; (int = 0; < out.rows; i++) { (int j = 0; j < out.cols; j++) { out.at<cv::vec3d>(i, j) = im.at<cv::vec3d>(im.rows-1-j, i); /* *if (tmp<1000) {tmp++;} *else {imwrite("/tmp/out.png", out); tmp=0;} */ } } imwrite("/tmp/in.png", im); imwrite("/tmp/out.png", out); homecoming 0; }

i noticed width in out image stretched 3 times (1px→3px). plus, segmentation fault @ return.

update:

here’s pseudo-code:

for(row=0; row<out.rows; row++) { for(col = 0; col<out.cols; col++) { out[row][col] = in[(in.rows-1)-col][row]; } }

you reading image grayscale image: cv::imread(name, 0).

you should alter to: cv::imread(name, 1), otherwise cannot utilize im.at<cv::vec3b>(i, j) (notice vec3b, instead of vec3d, b stands unsigned char, d means double)

c++ opencv rotation segmentation-fault

No comments:

Post a Comment