QT 插件化圖像算法研究平臺(tái)的功能在持續(xù)完善,補(bǔ)充了一個(gè)人工選擇圖片區(qū)域的功能。
其中,圖片選擇功能主要代碼如下:
QRect GLImageWidget::getSeleted()
{
QRect ajust(0,0,0,0);
if(image.isNull() || !hasSelection)return ajust;
double w=1.0* imageSize.width()/ adaptImageSize.width();
double h=1.0* imageSize.height()/ adaptImageSize.height();
ajust.setLeft((selection.left()-leftPos)*w/scaleVal);
ajust.setWidth(selection.width()*w/scaleVal);
ajust.setTop((selection.top()-topPos)*h/scaleVal);
ajust.setHeight(selection.height()*h/scaleVal);
return ajust;
}
需要考慮因素:圖片原始大小、窗口大小、圖片顯示在窗口的大小、圖片在窗口的移動(dòng)位置、圖片在窗口的縮放、用戶在窗口上框選的矩陣。
手工選擇圖片區(qū)域去水印 效果如下:左上角人工框選處的文字給去除了。
文章來源:http://www.zghlxwxcb.cn/news/detail-695546.html
主要代碼參考如下:文章來源地址http://www.zghlxwxcb.cn/news/detail-695546.html
void deWaterMarkSelection(Mat &input,Mat &output,Mat &src,string)
{
auto selectRect= processWinGetSelection();
if(selectRect.width()==0)
{
output=input;
return;
}
Mat mask = Mat::zeros(input.size(), CV_8U);
auto topLeft=selectRect.topLeft();
auto bottomRight=selectRect.bottomRight();
Point rookPoints[1][4];
rookPoints[0][0] =Point(topLeft.x(),topLeft.y());//左上角
rookPoints[0][1] = Point(bottomRight.x(),topLeft.y());//右上角
rookPoints[0][2] = Point(bottomRight.x(),bottomRight.y());//右下角
rookPoints[0][3] =Point(topLeft.x(),bottomRight.y());//左下角
int npt[]={4};//二維數(shù)組 每列長度
const Point* ppt[1] = {rookPoints[0]};//所有多邊形點(diǎn)坐標(biāo)
fillPoly(mask, ppt, npt, 1, Scalar::all(255));
//使用inpaint進(jìn)行圖像修復(fù)
Mat result;
inpaint(src, mask, output, 1, INPAINT_NS);
}
到了這里,關(guān)于Opencv手工選擇圖片區(qū)域去水印的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!