图像缩放算法_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
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缩放算法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: h5上传图片_怎么搭建自己的H5响应式网
- 下一篇: nodejs源码_格物致知记一次node