fork download
  1. import cv2
  2. import numpy as np
  3. from matplotlib import pyplot as plt
  4.  
  5. img_rgb = cv2.imread('all_cards.png')
  6. img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
  7. # cv2.imshow("123",img_gray)
  8. # cv2.waitKey(0)
  9. template = cv2.imread('8d.png',0)
  10. w, h = template.shape[::-1]
  11.  
  12. res = cv2.matchTemplate(img_gray,template,cv2.TM_CCOEFF_NORMED)
  13. # cv2.namedWindow('image', cv2.WINDOW_NORMAL)
  14. # cv2.imshow("123",res)
  15. #
  16. # cv2.waitKey(0)
  17.  
  18. threshold = 0.95
  19. loc = np.where( res >= threshold)
  20. for pt in zip(*loc[::-1]):
  21. cv2.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0,0,255), 2)
  22.  
  23. cv2.imwrite('res.png',img_rgb)
  24.  
Runtime error #stdin #stdout #stderr 0s 9992KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 1, in <module>
ImportError: No module named 'cv2'