Home > database >  Find out if a cell in the form is selected or not selected
Find out if a cell in the form is selected or not selected

Time:07-21

Good afternoon. My task is to take a questionnaire and write the selected options into the database, according to the type true or false. With the help of Microsoft Recognize, I get the desired table and then with the help of cm2, I make a crop of the image to understand whether it is true or false.

imagePage = cv2.imread(image.path)
x = int(coordinates[0])
y = int(coordinates[1])
w = int(coordinates[2])
h = int(coordinates[3])
imageCell = imagePage[y:y h, x:x w]
cv2.rectangle(imagePage, (x, y), (x   w, y   h), (0, 255, 0), 3)

Table with selected cells:

Table with selected cells

Next, the idea was to check by the presence of black pixels. If there are many of them, then the item has been selected and it is true. Unfortunately, this does not work, because the border of the lines, which are also considered black pixels, fall.

def countBlackPixels(imageCell):
lowerBlack = np.array([0, 0, 0], np.uint8)
blackRange = cv2.inRange(imageCell, lowerBlack, lowerBlack)
blackPixels = cv2.countNonZero(blackRange)
return blackPixels

For example, one cell with X shows 258 black pixels, the second cell with X shows 98.

Are there any ways to read in the questionnaire the answers to the cells that are presented in the format: X, V?

CodePudding user response:

The difference between two cells in terms of number of black cells felt like way too high.

This is possibly be the result of selection of borders in a given cell.

I wonder what is the result of

def countBlackPixels(imageCell):

for an empty cell.

Maybe we can set a threshold from this value to decide whether or not a cell is checked.

If that does not look promising, maybe we can rewrite the countBlackPixels() to look for the center area of the cell specifically.

Something like this:

Something like this

Waiting to hear from you!

  • Related