【opencv | 您所在的位置:网站首页 › opencv源代码怎么看 › 【opencv |
1、网上手册查询
A. 打开Welcome to opencv documentation B. 在左侧输入要查询的函数, 如图1.1,假设我们要查询resize函数 C. 点击Search按钮后可以看到结果,如图1.2 D. 点开第一条函数说明,进去查找到resize函数,如图1.3 从图1.3中可以看到在python中的resize函数说明为 cv2.resize(src, dsize[, dst[, fx[, fy[, interpolation]]]]) → dst[, dst[, fx[, fy[, interpolation]]]])意味着这些参数是可选参数 → dst意味着函数返回dst 参数说明Parameters可以看到参数的具体含义 D.A: src – input image, src为输入图片 D.B: dst, dst为输出图片 D.C: dsize, dsize为输出图片大小,当它为0时,要计算dsize = Size(round(fx*src.cols), round(fy&src.rows)),由这句话可以得出当dsize=0时,要同时输入src、fx、fy D.D: fx, 水平缩放倍率,当它为0时则有fx = (double)dsize.width/src.clos D.E: fy, 垂直缩放倍率,当它为0时则有fy = (double)dsize.height/src.rows D.F: interpolation插值,主要有以下几个选项 INTER_NEAREST INTER_LINEAR INTER_AREA INTER_CUBIC INTER_LANCZOS4 根据D.C、D.D、D.E可知道定有dsize和fx、fy两种方式可以指定输出图片大小。dsize方式 dsize=(180, 180)fx、fy方式 fx=2, fy=2如果dsize和fx、fy都存在,先计算dsize,如果dsize=None, 则输出图片大小为fx、fy,如果dsize!=None, 则为dsize。 阅读了上面的说明,我们知道resize可以像下面这样用 # 只指定src和dsize res = cv2.resize(src=img, dsize=(2*width, 2*height)) # 只指定src、dsize和interpolation res = cv2.resize(src=img, dsize=(2*width, 2*height), interpolation = cv2.INTER_LINEAR) # 只指定src、dsize、fx、fy res = cv2.resize(src=img, dsize=None, fx=0.5, fy = 0.5) # 只指定src、dsize、fx、fy和interpolation res = cv2.resize(src=img, dsize=None, fx=0.5, fy = 0.5, interpolation = cv2.INTER_LINEAR) 2、使用help命令查看A. 在CMD中运行python进入python模式中 F:\QAQ\python\opencv>python Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 bit (AM D64)] on win32 Type "help", "copyright", "credits" or "license" for more information.B. 导入cv2模块 >>> import cv2C. 使用help查看cv2.resize函数 >>> help(cv2.resize) Help on built-in function resize: resize(...) resize(src, dsize[, dst[, fx[, fy[, interpolation]]]]) -> dst . @brief Resizes an image. . . The function resize resizes the image src down to or up to the specified size. Note that the . initial dst type or size are not taken into account. Instead, the size a nd type are derived from . the `src`,`dsize`,`fx`, and `fy`. If you want to resize src so that it f its the pre-created dst, . you may call the function as follows: . @code . // explicitly specify dsize=dst.size(); fx and fy will be computed from that. . resize(src, dst, dst.size(), 0, 0, interpolation); . @endcode . If you want to decimate the image by factor of 2 in each direction, you can call the function this . way: . @code . // specify fx and fy and let the function compute the destination image size. . resize(src, dst, Size(), 0.5, 0.5, interpolation); . @endcode . To shrink an image, it will generally look best with cv::INTER_AREA inte rpolation, whereas to . enlarge an image, it will generally look best with cv::INTER_CUBIC (slow ) or cv::INTER_LINEAR . (faster but still looks OK). . . @param src input image. . @param dst output image; it has the size dsize (when it is non-zero) or the size computed from . src.size(), fx, and fy; the type of dst is the same as of src. . @param dsize output image size; if it equals zero, it is computed as: . \f[\texttt{dsize = Size(round(fx*src.cols), round(fy*src.rows))}\f] . Either dsize or both fx and fy must be non-zero. . @param fx scale factor along the horizontal axis; when it equals 0, it i s computed as . \f[\texttt{(double)dsize.width/src.cols}\f] . @param fy scale factor along the vertical axis; when it equals 0, it is computed as . \f[\texttt{(double)dsize.height/src.rows}\f] . @param interpolation interpolation method, see cv::InterpolationFlags . . @sa warpAffine, warpPerspective, remap |
CopyRight 2018-2019 实验室设备网 版权所有 |