我对opencv和使用python的深入学习非常陌生。我试图从图像中删除水印/徽标。通过在图像中的原始图像中找到裁剪的水印图像的位置,可以找到水印的位置,这是所有图像的常数。我需要移除找到的水印。
这是原始图像:原始image2:原始image3:
从原始图像中剪切的水印图像:
在图像中定位水印:我尝试了使用tensorflow/深度学习的各种代码,在此代码下,din不会泛化,并在运行它们时给出了各种错误。
例如,我尝试过自动水印检测( https://github.com/rohitrango/automatic-watermark-detection),但它不起作用。这个库中的crop_watermark()函数没有工作,因为我的image.It正在剪切图像的其他部分,这不是水标记,还有许多其他的代码问题。
类似地,我尝试了许多其他的深造图书馆,没有运气。
我也在考虑尝试cv2.inpaint(img,mask,3,cv2.INPAINT_TELEA),但我没有面具图像。我只有一张图像上有水印,如下所示,所以不能使用inpaint()函数。
目前正在尝试以下简单的代码来找出水印在图像中的准确位置(通过手工裁剪水印并在原始图像中找到位置)。
import numpy as np
import cv2
img = cv2.imread('original_image.jpeg')
print(img.shape)
h,w,c = img.shape
logo = cv2.imread("cropped_image.jpeg")
print(logo.shape)
hl,wl,cl = logo.shape
x1 = int(w/2-wl/2)
y1 = int(h/2-hl)
x2 = int(w/2+wl/2)
y2 = int(h/2)
cv2.rectangle(img, (x1, y1), (x2, y2), (255,0,0), 2)
cv2.imwrite("my.png",img)
cv2.imshow("lalala", img)以上代码能够找到正确的水印坐标。从现在开始,我不知道如何去除水印。如果您能够提供一些示例代码以及概念,那就太棒了。
谢谢你的帮助。
发布于 2019-04-23 12:31:59
您可以尝试OpenCV 模块的OpenCV函数,您首先需要创建一个掩码,并指示图像上徽标所在的区域,然后传递图像和掩码,然后将结果存储在目标图像中。
@param src source image, it could be of any type and any number of channels from 1 to 4. In case of
3- and 4-channels images the function expect them in CIELab colorspace or similar one, where first
color component shows intensity, while second and third shows colors. Nonetheless you can try any
colorspaces.
@param mask mask (CV_8UC1), where non-zero pixels indicate valid image area, while zero pixels
indicate area to be inpainted
@param dst destination image
@param algorithmType see xphoto::InpaintTypes
*/
CV_EXPORTS_W void inpaint(const Mat &src, const Mat &mask, Mat &dst, const int algorithmType);创建掩码的一些提示:当您通过一些工具(图像编辑器)创建掩码图像时,背景必须是黑色的,徽标区域必须是白色的。然后,当之前创建的图像用作掩码时,首先应该将图像转换为灰色,然后使用THRESH_BINARY标志对图像进行阈值化。
更新:实现,这是代码,它在C++中,但是您可以考虑这些步骤,这都是一样的。
cv::namedWindow("Original_Image", cv::WINDOW_FREERATIO);
cv::namedWindow("Result", cv::WINDOW_FREERATIO);
cv::Mat originalImg = cv::imread("y25av.jpg");
cv::Mat mask = cv::imread("mask.jpg");
// to gray
cv::Mat gray;
cv::cvtColor(mask, gray, cv::COLOR_BGR2GRAY);
cv::threshold(gray, mask, 180, 255, cv::THRESH_BINARY);
cv::Mat dst;
cv::inpaint(originalImg, mask, dst, 10, cv::INPAINT_TELEA);
cv::imshow("Original_Image", originalImg);
cv::imshow("Result", dst);
cv::waitKey();您的原始图像:

使用的掩码:

最终结果:

https://stackoverflow.com/questions/55811122
复制相似问题