Note that there are some explanatory texts on larger screens.

plurals
  1. POOpenCV find coloured in circle and position value Python
    primarykey
    data
    text
    <p>What I'm trying to do is process the attendance sheet below to tell me who's there and who's not <img src="https://i.stack.imgur.com/uYcGC.png" alt="Attendance Sheet"></p> <p>I'm currently using matchTemplate using a singular black dot which finds all the filled in dots (image is first converted to grey scale). Image below</p> <p><img src="https://i.stack.imgur.com/NoMdz.png" alt="Dots Matched"></p> <p>Then I get manipulate the matchPattern array and get approximately the center of each in the y direction and I can see where there are gaps corresponding to missing students.</p> <p>The issue I am having is that sure this sorta works for perfect input but my goal is to be able to take a picture of the physical piece of paper and process this? Note: the attendance sheet is made by me so it can be changed/modified however necessary.</p> <p>I have attached an example image to match seen below. <img src="https://i.stack.imgur.com/TCSTi.jpg" alt="test match"> Using my current method is just a disaster (seen below). Now I'm not sure where to go from here I tried modifying the threshold but past .65 it fails to find any images. <img src="https://i.stack.imgur.com/xX0qM.jpg" alt="fail"></p> <pre><code>import cv2 import numpy as np from matplotlib import pyplot as plt values = [] img_rgb = cv2.imread('/home/user/Downloads/input.png') img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY) template = cv2.imread('/home/user/Downloads/input_2.png',0) w, h = template.shape[::-1] res = cv2.matchTemplate(img_gray,template,cv2.TM_CCOEFF_NORMED) threshold = 0.6 loc = np.where( res &gt;= threshold) for pt in zip(*loc[::-1]): cv2.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0,0,255), 2) values.append(pt[1]+h/2) cv2.imwrite('output.png',img_rgb) values.sort() pivot = values[0] count = 1 total = values[0] cleaned = [] for x in range(1,len(values)): if(values[x] &lt; pivot+20): pivot = values[x] count = count + 1 total = total + values[x] else: print values[x] cleaned.append(int(total/count)) pivot = values[x] count = 1 total = values[x] if x == len(values)-1: cleaned.append(int(total/count)) print values print cleaned </code></pre> <p>Here is another test image: <img src="https://i.stack.imgur.com/Qcy5R.jpg" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload