Testing Image Watermark Detection Implementation in Stable Diffusion
This test suite implements watermark detection functionality for the Stable Diffusion project, focusing on verifying the proper decoding of embedded watermarks in images. The test utilizes OpenCV and the imwatermark library to extract and validate watermark data from image files.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
stability-ai/stablediffusion
scripts/tests/test_watermark.py
import cv2
import fire
from imwatermark import WatermarkDecoder
def testit(img_path):
bgr = cv2.imread(img_path)
decoder = WatermarkDecoder('bytes', 136)
watermark = decoder.decode(bgr, 'dwtDct')
try:
dec = watermark.decode('utf-8')
except:
dec = "null"
print(dec)
if __name__ == "__main__":
fire.Fire(testit)