Advertisement
WarPie90

Untitled

May 18th, 2014
471
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.60 KB | None | 0 0
  1. // Procedure cv_LoadImage(ImFile:PChar; var Mat: Pointer; var Width,Height:Int32);
  2. void loadImage(char* imfile, Mat** cvImage, int &Width, int &Height)
  3. {
  4.     Mat* res = new Mat();
  5.     *res = imread(imfile);
  6.     if (res->empty())
  7.     {
  8.         cout << "Cannot load image!" << endl;
  9.         cvImage = NULL;
  10.         return;
  11.     }
  12.     Width = res->cols;
  13.     Height = res->rows;
  14.     *cvImage = res;
  15. }
  16.  
  17.  
  18. // Procedure cv_FreeImage(var Mat: Pointer);
  19. void freeImage(Mat** cvImage) {
  20.     Mat* res = *cvImage;
  21.     res->release();
  22.     delete *cvImage;
  23.     *cvImage = NULL;
  24. }
  25.  
  26.  
  27. // Function cv_MatchTemplate(var Sub,Img:Pointer; MatchMethod: Int32; var Mat: Pointer): Pointer;
  28. float* matchTemplate(Mat* &templ, Mat* &im, int matchMethod, Mat** result)
  29. {
  30.     if ((matchMethod < 0) || (matchMethod > 5))
  31.     {
  32.         cout << "Undefined matchMethod! Should be in range of 0-5" << endl;
  33.         return NULL;
  34.     }
  35.  
  36.     if ((im->type() != templ->type()) || (im->depth() != templ->depth()))
  37.     {
  38.         cout << "[Error]: " << endl;
  39.         cout << "\t-> type:\t" << templ->type() << ", " << im->type() << endl;
  40.         cout << "\t-> depth:\t" << templ->depth() << ", " << im->depth() << endl;
  41.         return NULL;
  42.     }
  43.  
  44.     Mat* res = new Mat();
  45.  
  46.     int result_cols =    im->cols - templ->cols + 1;
  47.     int result_rows = im->rows - templ->rows + 1;
  48.     res->create( result_cols, result_rows, CV_32FC1 );
  49.  
  50.     //cout << "Processing..." << endl;
  51.     matchTemplate( *im, *templ, *res, matchMethod );
  52.     normalize( *res, *res, 0, 1, NORM_MINMAX, -1, Mat() );
  53.     *result = res;
  54.  
  55.     return (float*)res->data;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement