天天看點

Python+OpenCV識别圖檔中是否有紅章

import matplotlib.pyplot as plt
import cv2
import numpy as np

img = cv2.imread("4.jpg")
img_hsv = cv2.cvtColor(img, cv2.COLOR_RGB2HSV)

lower_blue = np.array([100, 30, 100])
upper_blue = np.array([150, 255, 255])

mask = cv2.inRange(img_hsv, lower_blue, upper_blue)

res = cv2.bitwise_and(img, img, mask=mask)
r, g, b = cv2.split(res)
r_num = 0
for i in b:
    for j in i:
        if j > 170:
            r_num += 1
# cv2.imshow('img', img)
# cv2.imshow("mask", mask)
cv2.imshow("res", res)

if(r_num>30):
    print("該圖檔有紅章")
else:
    print("該圖檔沒有紅章")
print(r_num)
cv2.waitKey(0)

           

這裡給出幾個自己的例子

Python+OpenCV識别圖檔中是否有紅章
Python+OpenCV識别圖檔中是否有紅章
Python+OpenCV識别圖檔中是否有紅章