CV_EXPORTS_W Mat imread( const String& filename,int flags = IMREAD_COLOR );enumImreadModes { IMREAD_UNCHANGED =-1,//!< If set, return the loaded image as is (with alpha channel, otherwise it gets cropped). Ignore EXIF orientation. IMREAD_GRAYSCALE =0,//!< If set, always convert image to the single channel grayscale image (codec internal conversion). IMREAD_COLOR =1,//!< If set, always convert image to the 3 channel BGR color image. IMREAD_ANYDEPTH =2,//!< If set, return 16-bit/32-bit image when the input has the corresponding depth, otherwise convert it to 8-bit. IMREAD_ANYCOLOR =4,//!< If set, the image is read in any possible color format. IMREAD_LOAD_GDAL =8,//!< If set, use the gdal driver for loading the image. IMREAD_REDUCED_GRAYSCALE_2 =16,//!< If set, always convert image to the single channel grayscale image and the image size reduced 1/2. IMREAD_REDUCED_COLOR_2 =17,//!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/2. IMREAD_REDUCED_GRAYSCALE_4 =32,//!< If set, always convert image to the single channel grayscale image and the image size reduced 1/4. IMREAD_REDUCED_COLOR_4 =33,//!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/4. IMREAD_REDUCED_GRAYSCALE_8 =64,//!< If set, always convert image to the single channel grayscale image and the image size reduced 1/8. IMREAD_REDUCED_COLOR_8 =65,//!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/8. IMREAD_IGNORE_ORIENTATION =128//!< If set, do not rotate the image according to EXIF's orientation flag. };
enumInterpolationFlags{ /** nearest neighbor interpolation */ INTER_NEAREST =0, /** bilinear interpolation */ INTER_LINEAR =1, /** bicubic interpolation */ INTER_CUBIC =2, /** resampling using pixel area relation. It may be a preferred method for image decimation, as it gives moire'-free results. But when the image is zoomed, it is similar to the INTER_NEAREST method. */ INTER_AREA =3, /** Lanczos interpolation over 8x8 neighborhood */ INTER_LANCZOS4 =4, /** Bit exact bilinear interpolation */ INTER_LINEAR_EXACT =5, /** Bit exact nearest neighbor interpolation. This will produce same results as the nearest neighbor method in PIL, scikit-image or Matlab. */ INTER_NEAREST_EXACT =6, /** mask for interpolation codes */ INTER_MAX =7, /** flag, fills all of the destination image pixels. If some of them correspond to outliers in the source image, they are set to zero */ WARP_FILL_OUTLIERS =8, /** flag, inverse transformation For example, #linearPolar or #logPolar transforms: - flag is __not__ set: \f$dst( \rho , \phi ) = src(x,y)\f$ - flag is set: \f$dst(x,y) = src( \rho , \phi )\f$ */ WARP_INVERSE_MAP =16};
inlineMat Mat::operator()( constRect& roi ) const{returnMat(*this, roi);}
以下为实例
Mat xuenai =imread("xuenai.jpg");resize(xuenai,xuenai,Size(1000,1000));imshow("xuenai", xuenai);Mattuanzi(xuenai,(Rect(0,0,500,1000)));imshow("tuanzi",tuanzi);waitKey();
13.2 方式二
Mat::Mat(const Mat& m,const Rect& roi);
以下为实例
Mat xuenai =imread("xuenai.jpg");resize(xuenai,xuenai,Size(1000,1000));imshow("xuenai", xuenai);Mattuanzi(xuenai(Rect(0,0,500,1000)));imshow("tuanzi",tuanzi);waitKey();
Mat xuenai =imread("xuenai.jpg");imshow("xuenai",xuenai);double M_values[]={1,0,200,0,1,200};MatM(Size(3,2),CV_64F,M_values);Matxuenai_shift(xuenai.size(),xuenai.type());warpAffine(xuenai,xuenai_shift,M,xuenai.size());imshow("xuenai_shift",xuenai_shift);waitKet();
Mat xuenai =imread("xuenai.jpg");imshow("xuenai", xuenai);Mat M=getRotationMatrix2D(Point2f(xuenai.cols/2,xuenai.rows/2),45,1);Matxuenai_rotate(xuenai.size(),xuenai.type());warpAffine(xuenai,xuenai_rotate,M,xuenai.size());imshow("xuenai_flip",xuenai_rotate);
15.4 仿射(不破坏几何关系)
获得变换矩阵M
CV_EXPORTS Mat getAffineTransform( const Point2f src[],const Point2f dst[] );