aihot  2017-05-24 18:31:03  OpenCV |   查看评论   

  测试代码test_resize.cpp:

  1. #include <assert.h>  
  2. #include <core/mat.hpp>  
  3. #include <resize.hpp>  
  4.   
  5. #include <opencv2/opencv.hpp>  
  6.   
  7. #include "test_resize.hpp"  
  8.   
  9. int test_resize_uchar()  
  10. {  
  11.     cv::Mat mat = cv::imread("E:/GitCode/OpenCV_Test/test_images/lena.png", 1);  
  12.     if (!mat.data) {  
  13.         std::cout << "read image fail" << std::endl;  
  14.         return -1;  
  15.     }  
  16.   
  17.     int width = 23, height = 11;  
  18.   
  19.     for (int inter = 0; inter < 5; inter++) {  
  20.         fbc::Mat3BGR mat1(mat.rows, mat.cols, mat.data);  
  21.         fbc::Mat3BGR mat2(mat1);  
  22.         fbc::Mat3BGR mat3(height, width);  
  23.         fbc::resize(mat2, mat3, inter);  
  24.   
  25.         cv::Mat mat1_(mat.rows, mat.cols, CV_8UC3, mat.data);  
  26.         cv::Mat mat2_;  
  27.         mat1_.copyTo(mat2_);  
  28.         cv::Mat mat3_(height, width, CV_8UC3);  
  29.         cv::resize(mat2_, mat3_, cv::Size(width, height), 0, 0, inter);  
  30.   
  31.         assert(mat3.step == mat3_.step);  
  32.         for (int y = 0; y < mat3.rows; y++) {  
  33.             const fbc::uchar* p = mat3.ptr(y);  
  34.             const uchar* p_ = mat3_.ptr(y);  
  35.   
  36.             for (int x = 0; x < mat3.step; x++) {  
  37.                 assert(p[x] == p_[x]);  
  38.             }  
  39.         }  
  40.     }  
  41.   
  42.     return 0;  
  43. }  
  44.   
  45. int test_resize_float()  
  46. {  
  47.     cv::Mat mat = cv::imread("E:/GitCode/OpenCV_Test/test_images/lena.png", 1);  
  48.     if (!mat.data) {  
  49.         std::cout << "read image fail" << std::endl;  
  50.         return -1;  
  51.     }  
  52.     int width = 623, height = 711;  
  53.     cv::cvtColor(mat, mat, CV_BGR2GRAY);  
  54.     mat.convertTo(mat, CV_32FC1);  
  55.   
  56.     for (int inter = 0; inter < 5; inter++) {  
  57.         fbc::Mat_<float, 1> mat1(mat.rows, mat.cols, mat.data);  
  58.         fbc::Mat_<float, 1> mat2(mat1);  
  59.         fbc::Mat_<float, 1> mat3(height, width);  
  60.         fbc::resize(mat2, mat3, inter);  
  61.   
  62.         cv::Mat mat1_(mat.rows, mat.cols, CV_32FC1, mat.data);  
  63.         cv::Mat mat2_;  
  64.         mat1_.copyTo(mat2_);  
  65.         cv::Mat mat3_(height, width, CV_32FC1);  
  66.         cv::resize(mat2_, mat3_, cv::Size(width, height), 0, 0, inter);  
  67.   
  68.         assert(mat3.step == mat3_.step);  
  69.         for (int y = 0; y < mat3.rows; y++) {  
  70.             const fbc::uchar* p = mat3.ptr(y);  
  71.             const uchar* p_ = mat3_.ptr(y);  
  72.   
  73.             for (int x = 0; x < mat3.step; x++) {  
  74.                 assert(p[x] == p_[x]);  
  75.             }  
  76.         }  
  77.     }  
  78.   
  79.     return 0;  
  80. }  
  81.   
  82. int test_resize_area()  
  83. {  
  84.     cv::Mat mat = cv::imread("E:/GitCode/OpenCV_Test/test_images/lena.png", 1);  
  85.     if (!mat.data) {  
  86.         std::cout << "read image fail" << std::endl;  
  87.         return -1;  
  88.     }  
  89.     fbc::Size size[3] = {fbc::Size(123, 111), fbc::Size(256, 256), fbc::Size(723, 817)};  
  90.   
  91.     for (int i = 0; i < 3; i++) {  
  92.         fbc::Mat3BGR mat1(mat.rows, mat.cols, mat.data);  
  93.         fbc::Mat3BGR mat2(mat1);  
  94.         fbc::Mat3BGR mat3(size[i].height, size[i].width);  
  95.         fbc::resize(mat2, mat3, 3);  
  96.   
  97.         cv::Mat mat1_(mat.rows, mat.cols, CV_8UC3, mat.data);  
  98.         cv::Mat mat2_;  
  99.         mat1_.copyTo(mat2_);  
  100.         cv::Mat mat3_(size[i].height, size[i].width, CV_8UC3);  
  101.         cv::resize(mat2_, mat3_, cv::Size(size[i].width, size[i].height), 0, 0, 3);  
  102.   
  103.         assert(mat3.step == mat3_.step);  
  104.         for (int y = 0; y < mat3.rows; y++) {  
  105.             const fbc::uchar* p = mat3.ptr(y);  
  106.             const uchar* p_ = mat3_.ptr(y);  
  107.   
  108.             for (int x = 0; x < mat3.step; x++) {  
  109.                 assert(p[x] == p_[x]);  
  110.             }  
  111.         }  
  112.     }  
  113.   
  114.     cv::Mat matf;  
  115.     cv::cvtColor(mat, matf, CV_BGR2GRAY);  
  116.     matf.convertTo(matf, CV_32FC1);  
  117.   
  118.     for (int i = 0; i < 3; i++) {  
  119.         fbc::Mat_<float, 1> mat1(mat.rows, mat.cols, matf.data);  
  120.         fbc::Mat_<float, 1> mat2(mat1);  
  121.         fbc::Mat_<float, 1> mat3(size[i].height, size[i].width);  
  122.         fbc::resize(mat2, mat3, 3);  
  123.   
  124.         cv::Mat mat1_(mat.rows, mat.cols, CV_32FC1, matf.data);  
  125.         cv::Mat mat2_;  
  126.         mat1_.copyTo(mat2_);  
  127.         cv::Mat mat3_(size[i].height, size[i].width, CV_32FC1);  
  128.         cv::resize(mat2_, mat3_, cv::Size(size[i].width, size[i].height), 0, 0, 3);  
  129.   
  130.         assert(mat3.step == mat3_.step);  
  131.         for (int y = 0; y < mat3.rows; y++) {  
  132.             const fbc::uchar* p = mat3.ptr(y);  
  133.             const uchar* p_ = mat3_.ptr(y);  
  134.   
  135.             for (int x = 0; x < mat3.step; x++) {  
  136.                 assert(p[x] == p_[x]);  
  137.             }  
  138.         }  
  139.     }  
  140.   
  141.     return 0;  
  142. }  
 

除特别注明外,本站所有文章均为 赢咖4注册 原创,转载请注明出处来自OpenCV代码提取:resize函数的实现

留言与评论(共有 0 条评论)
   
验证码:
[lianlun]1[/lianlun]