日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

图像缩放算法_opencv缩放算法

發布時間:2024/9/3 52 豆豆
生活随笔 收集整理的這篇文章主要介紹了 图像缩放算法_opencv缩放算法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.opencv插值介紹

opencv提供resize函數用來做圖像縮放,該函數有6個參數:

(1)輸入圖像,Mat型

(2)輸出圖像,Mat型

(3)輸出圖像大小,可用cv::Size(out_img_width, out_img_height)來表示,如果該值為0,則輸出大小由第4,5兩個參數fx、fy決定

(4)水平縮放因子,如果該值為0,則會按照(double)dsize.width/src.cols來計算

(5)重直縮放因子,如果該值為0,則會按照(double)dsize.height/src.rows來計算

(6)插值算法,可以選擇各種插值算法,INTERNEAREST效果較差,優點是速度快,INTER

2.插值參數選擇

opencv文檔及代碼寫的很清楚了,這里就不再細說,實際使用上,對于放大場景來說,雙立方插值INTER_CUBIC與lanczos插值INTER_LANCZOS4效果較好,而縮小場景,效果最好的算法為INTER_AREA。

  • INTER_NEAREST - a nearest-neighbor interpolation
  • INTER_LINEAR - a bilinear interpolation (used by default)
  • INTER_AREA - 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_CUBIC - a bicubic interpolation over 4x4 pixel neighborhood
  • INTER_LANCZOS4 - a Lanczos interpolation over 8x8 pixel neighborhood
enum InterpolationFlags{/** 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, asit gives moire'-free results. But when the image is zoomed, it is similar to the INTER_NEARESTmethod. */INTER_AREA = 3,/** Lanczos interpolation over 8x8 neighborhood */INTER_LANCZOS4 = 4,/** Bit exact bilinear interpolation */INTER_LINEAR_EXACT = 5,/** mask for interpolation codes */INTER_MAX = 7,/** flag, fills all of the destination image pixels. If some of them correspond to outliers in thesource image, they are set to zero */WARP_FILL_OUTLIERS = 8,/** flag, inverse transformationFor 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 };

3.demo

img_decode為輸入圖像,img_resize為輸出圖像

resize(img_decode, img_resize, Size(img_dst_width, img_dst_height), 0, 0, INTER_LANCZOS4);

下面為縮小case,原圖分辨率為633x773,目標分辨率為286x350,如下分別為面積插值、雙線性、lanczos效果,縮小時面積關聯法效果最佳:

參考

[1] https://docs.opencv.org/2.4/modules/imgproc/doc/geometric_transformations.html?highlight=resize

總結

以上是生活随笔為你收集整理的图像缩放算法_opencv缩放算法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。