C++ 从一幅图片上裁取需要的区域
生活随笔
收集整理的這篇文章主要介紹了
C++ 从一幅图片上裁取需要的区域
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
1、Mat
Mat src, image_src; //原圖 Mat imageROI; //ROI區(qū)域 Mat TempImg; //裁取出的區(qū)域存儲為Mat int x_begin, y_begin, width, height; //裁取區(qū)域的坐標(biāo)及大小 int srcWidth, srcHeight; //存儲原圖寬、高//賦初值 x_begin = 0; y_begin = 0; width = 100; height = 100;//讀取原圖 src = imread("test.jpg", 1); if(!src.data){cout<<" image read error!"<<endl;return -1; } srcWidth = src.cols; //獲取原圖寬、高 srcHeight = src.rows;//控制裁取區(qū)域不超過原圖 if(width < 1 || height < 1 || width > srcWidth || height > srcHeight){LOOGE<<"[Rect error: srcWidth = "<<srcWidth<<", srcHeight = "<<srcHeight<<", x_begin = "<<x_begin<<", y_begin = "<<y_begin<<", width = "<<width<<", height = "<<height<<" ]";return -1; } if(x_begin + width > srcWidth) width = srcWidth - x_begin; if(y_begin + height > srcHeight)height = srcHeight - y_begin;//區(qū)域裁取 image_src = src.clone(); //備份原圖 imageROI = image_src(Rect(x_begin, y_begin, width, height)); //設(shè)置待裁取ROI imageROI.convertTo(TempImg, TempImg.type()); //將ROI區(qū)域拷貝至dst
總結(jié)
以上是生活随笔為你收集整理的C++ 从一幅图片上裁取需要的区域的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 搞ERP的和搞低代码的别鸡同鸭讲,还是走
- 下一篇: Linux Polkit本地权限提升漏洞