ait-survey

OpenCV-resize:tif->raw

Dec 5th, 2013
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.23 KB | None | 0 0
  1. #include <opencv2/core/core.hpp>
  2. #include <opencv2/imgproc/imgproc.hpp>
  3. #include <opencv2/highgui/highgui.hpp>
  4. #include <iostream>
  5. #include <cstdlib>
  6. #include <fstream>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10.  
  11. using namespace cv;
  12. using namespace std;
  13.  
  14. int
  15. main(int argc, char *argv[])
  16. {
  17.   FILE *fpo;
  18.   //ofstream out_img;
  19.   //out_img.open(argv[2],ios::out | ios::binary);
  20.   fpo=fopen(argv[2],"wb");
  21.  
  22.   cout << "check0\n" <<endl;
  23.  
  24.   Mat src_img = imread(argv[1], 2);
  25.   //Mat src_img = imread("depth_0010-01.tif", 2);
  26.   if(src_img.empty()) return -1;
  27.   //Mat dst_img1;
  28.   Mat dst_img2(src_img.rows*3.0, src_img.cols*3.0, CV_32FC1);
  29.  
  30.   cout << "check0-1\n" <<endl;
  31.  
  32.   //float *buffer;
  33.   //buffer=(float *)malloc(dst_img2.rows*dst_img2.cols*sizeof(float));
  34.  
  35.   cout << "check0-2\n" <<endl;
  36.  
  37.   // INTER_LINER(バイリニア補間)でのサイズ変更
  38.   //resize(src_img, dst_img1, Size(), 0.3, 0.3);
  39.   // INTER_CUBIC(バイキュービック補間)でのサイズ変更
  40.   //resize(src_img, dst_img2, dst_img2.size(), INTER_CUBIC);
  41.   resize(src_img,dst_img2,Size(),3.0,3.0,0);
  42.  
  43.   //namedWindow("resize image1", CV_WINDOW_AUTOSIZE|CV_WINDOW_FREERATIO);
  44.  namedWindow("resize image2", CV_WINDOW_AUTOSIZE|CV_WINDOW_FREERATIO);
  45.   //imshow("resize image1", dst_img1);
  46.   imshow("resize image2", dst_img2);
  47.  
  48.   cout << "check1\n" <<endl;
  49.  
  50.   cout << dst_img2.rows*dst_img2.cols << endl;
  51.  
  52.  float dn;
  53. /*
  54.   for(int i=0;i<src_img.rows*3; i++)
  55.   {
  56.      for(int j=0;j<src_img.cols*3; j++)
  57.      {
  58.         //out_img.put(dst_img2.data[i]);
  59.        // dn=(int)(dst_img2.data[i*dst_img2.cols+j]*10);
  60.  
  61.          // cout << dst_img2.data[i*dst_img2.cols+j] <<endl;
  62.         //cout << i <<endl;
  63.     //printf("%f\n",dn);
  64.    
  65.     //out_img.put(dst_img2.data[i*dst_img2.cols+j]);
  66.         dn=dst_img2.data[i*src_img.cols*3+j];
  67.         //out_img.write(dn,1);
  68.        //out_img <<
  69.        //fwrite(
  70.        //printf("%f\n",dn);
  71.        fwrite(&dn,sizeof(float),1,fpo);
  72.    
  73.      }
  74.   }
  75. */
  76.  
  77.   //out_img.write(dst_img2.data,dst_img2.rows*dst_img2.cols);
  78.  
  79.   fwrite(dst_img2.data,sizeof(float),dst_img2.rows*dst_img2.cols,fpo);
  80.   cout << "check2\n" <<endl;  
  81.  
  82.   //imwrite("output.tif",dst_img2);
  83.   fclose(fpo);
  84.    
  85.   waitKey(0);
  86.  
  87. }
Advertisement
Add Comment
Please, Sign In to add comment