O
O
object_Object2021-04-05 12:02:52
PHP
object_Object, 2021-04-05 12:02:52

How to recognize image on opencv?

Shalom everyone!
There is such a picture
Met6Egg.png
How can I recognize which pixels are lit and which are not and output them in the format 010101
where
0 is off
1 is on
Matrix 96x64 pixels

Thank you all in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Kuts, 2021-04-05
@object_Object

- align and crop the area with the screen
- perform the cv2.threshold operation by selecting the parameters
- reduce the image to 96x64
Get a matrix where the lines will contain the desired, if you change 255 to 1
Prototype:

import cv2

IMAGE = # <path>

image = cv2.imread(IMAGE)
image = image[0:720, 100:1000]

grey = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
(thresh, grey) = cv2.threshold(grey, 70, 255, cv2.THRESH_BINARY)
res = cv2.resize(grey,(96, 64), interpolation = cv2.INTER_CUBIC)

for im in res:
    out = ''.join(['1' if x else '0' for x in im])
    print(out)

606ad804f3e84809315649.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question