Advertisement
Kojima0502

resize_edit_write

Nov 29th, 2013
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.39 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.     float up;
  22.     up=atof(argv[3]);
  23.     cout << "check0\n" <<endl;
  24.    
  25.     Mat src_img = imread(argv[1], 2);
  26.     //Mat src_img = imread("depth_0010-01.tif", 2);
  27.     if(src_img.empty()) return -1;
  28.     //Mat dst_img1;
  29.     Mat dst_img2(src_img.rows*up, src_img.cols*up, CV_32FC1);
  30.    
  31.     cout << "check0-1\n" <<endl;
  32.    
  33.     //float *buffer;
  34.     //buffer=(float *)malloc(dst_img2.rows*dst_img2.cols*sizeof(float));
  35.    
  36.     cout << "check0-2\n" <<endl;
  37.    
  38.     // INTER_LINER(バイリニア補間)でのサイズ変更
  39.     //resize(src_img, dst_img1, Size(), 0.3, 0.3);
  40.     // INTER_CUBIC(バイキュービック補間)でのサイズ変更
  41.     //resize(src_img, dst_img2, dst_img2.size(), INTER_CUBIC);
  42.     resize(src_img,dst_img2,Size(),up,up,0);
  43.    
  44.     //namedWindow("resize image1", CV_WINDOW_AUTOSIZE|CV_WINDOW_FREERATIO);
  45.     namedWindow("resize image2", CV_WINDOW_AUTOSIZE|CV_WINDOW_FREERATIO);
  46.     //imshow("resize image1", dst_img1);
  47.     //imshow("resize image2", dst_img2);
  48.    
  49.     cout << "check1\n" <<endl;
  50.    
  51.     cout << dst_img2.rows*dst_img2.cols << endl;
  52.    
  53.     //float dn;
  54.     /*
  55.      for(int i=0;i<src_img.rows*3; i++)
  56.      {
  57.      for(int j=0;j<src_img.cols*3; j++)
  58.      {
  59.      //out_img.put(dst_img2.data[i]);
  60.      // dn=(int)(dst_img2.data[i*dst_img2.cols+j]*10);
  61.      
  62.      // cout << dst_img2.data[i*dst_img2.cols+j] <<endl;
  63.      //cout << i <<endl;
  64.      //printf("%f\n",dn);
  65.      
  66.      //out_img.put(dst_img2.data[i*dst_img2.cols+j]);
  67.      dn=dst_img2.data[i*src_img.cols*3+j];
  68.      //out_img.write(dn,1);
  69.      //out_img <<
  70.      //fwrite(
  71.      //printf("%f\n",dn);
  72.      fwrite(&dn,sizeof(float),1,fpo);
  73.      
  74.      }
  75.      }
  76.      */
  77.    
  78.     //out_img.write(dst_img2.data,dst_img2.rows*dst_img2.cols);
  79.    
  80.     fwrite(dst_img2.data,sizeof(float),dst_img2.rows*dst_img2.cols,fpo);
  81.     cout << "check2\n" <<endl;  
  82.    
  83.     //imwrite("output.tif",dst_img2);
  84.     fclose(fpo);
  85.    
  86.     waitKey(0);
  87.    
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement