Search

'Dectect'에 해당되는 글 1건

  1. 2020.06.02 [Python/OpenCV] Near-Duplicate Image Detection #1
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

import time
import cv2
import numpy as np
from mss import mss


print("load finger png files...")
imageFinger1 = cv2.imread("finger1.png")
imageFinger2 = cv2.imread("finger2.png")
imageFinger3 = cv2.imread("finger3.png")
imageFinger4 = cv2.imread("finger4.png")
print("load finger png files... Done")


with mss() as sct:
mon1 = sct.monitors[1]
mon2 = sct.monitors[2]
mon3 = sct.monitors[3]
mon4 = sct.monitors[4]
box = {'top': mon4['top'] +400, 'left': mon4['left'] + 200, 'width': 150, 'height': 190}
# mon = sct.monitors[0]
while True:
last_time = time.time()
capturedImage = np.array(sct.grab(box))
capturedImage = cv2.cvtColor(capturedImage, cv2.COLOR_BGRA2RGB)
imageFinger1 = cv2.cvtColor(imageFinger1, cv2.COLOR_BGRA2RGB)
imageFinger2 = cv2.cvtColor(imageFinger2, cv2.COLOR_BGRA2RGB)

#print('fps: {0}'.format(1 / (time.time()-last_time)))

#cv2.imshow('capturedImage', capturedImage)

difference = cv2.subtract(capturedImage, imageFinger1)
b, g, r = cv2.split(difference)
diff = cv2.countNonZero(b) + cv2.countNonZero(g) + cv2.countNonZero(r)
cv2.imshow('imageFinger1', difference)
print("png 1 diff = " + str(diff))
if diff == 0:
print("Detected finger png 1 !!!")
cv2.imshow('imageFinger1', difference )

difference = cv2.subtract(capturedImage, imageFinger2)
b, g, r = cv2.split(difference)
diff = cv2.countNonZero(b) + cv2.countNonZero(g) + cv2.countNonZero(r)
print("png b bbbb = " + str(b))
print("png b diff = " + str(cv2.countNonZero(b)))
print("png g diff = " + str(cv2.countNonZero(g)))
print("png r diff = " + str(cv2.countNonZero(r)))
cv2.imshow('imageFinger2', difference)
print("png 2 diff = " + str(diff))

if diff == 0:
print("Detected finger png 2 !!!")
cv2.imshow('imageFinger1', difference)


if cv2.waitKey(25) & 0xFF == ord('q'):
cv2.destroyAllWindows()
break




'Programming > Python' 카테고리의 다른 글

[Python/OpenCV] Near-Duplicate Image Detection #2  (0) 2020.06.02
[Python] List 정렬 프로그램 구현  (0) 2017.02.06
[Python 3.6] * 찍기  (0) 2017.02.02