How to detect checked box using python - python

I have the below PNG image and I am trying to identify which box is checked using Python.
I installed the OMR (optical mark recognition) package https://pypi.python.org/pypi/omr/0.0.7 but it wasn't any help and there wasn't any documentation about OMR.
So I need to know if there is any API or useful package I can use with Python.
Here is my image:

If you're not afraid of a little experimenting, the Python Imaging Library (PIL, download from http://www.pythonware.com/products/pil/ or your favorite repo. Manual: http://effbot.org/imagingbook/pil-index.htm) permits loading the PNG, and accessing it.
You can extract a section of the image (eg. the interior of a checkbox. See crop in the library), and sum the pixels in that sub-image (see point). Compare that with a threshold (say > 10 pixels = checked).
If the PNG comes from scanning forms, you may have to add some positional checking.

Related

OPENCV how do i map two slightly similar images in different orientation onto eachother

I have 2 images from different sources, and want to map them onto eachother because they both contain different information.
i am quite new to opencv and similar toolings, is there a way to automatically find the right orientation and location of the frame of the other image?
This is a classical image registration problem.
There are registration modules in scikit-image and opencv, though I am not sure how useful is the one in scikit-image: their examples only include shifts, but you also need rotations. The module in opencv includes different kinds of deformations and also provides tutorials on registration and alignment.
Another option would be to use the registration tool provided by the ANTs software

How to compress PNG image with S3TC/DXT algorithm in python?

I try to find way for compressing images(PNG as an example) with any S3TC/DXT algorithm using python libraries.
As I can see in Pillow(PIL) library DDS format in Read-only formats section. Therefore Pillow can't be used for this purpose.
Searching in google didn't give positive results.
Question:
Is it possible to do with python?
Could someone please provide link to libraries with such functional?(which is checked on practice)
DDS format is not mandatory for my case. I need only compressed file.
PS:
It's required for creating textures for future use.
Library should support different algorithms of compression.
You could use Python Wand. Here I create a pseudo image with a magenta-yellow gradient and save as DDS:
from wand.image import Image
with Image(width=200, height=80, pseudo='gradient:magenta-yellow') as img:
img.save(filename='result.dds')
Or, if you want to load a PNG file and save as DDS:
with Image(filename='input.png') as img:
img.save(filename='result.dds')

Color in image gets dull after saving it in OpenCV

I am using opencv module to read and write the image. here is the code and below is the image i am reading and second image is after saving it on disk using cv2.imwrite().
import cv2
img = cv2.imread('originalImage.jpg')
cv2.imwrite('test.jpg',img)
It is significantly visible that colors are dull in second image. Is there any workaround to this problem or I am missing on some sort of setting parameters..?
I have done a bit of research on the point #mark raised about ICC profile. I have figured out a way to handle this in python PIL module. here is the code that worked for me. I have also learned to use PNG file format rather JPEG to do lossless conversion.
import Image
img = Image.open('originalImage.jpg')
img.save('test.jpg',icc_profile=img.info.get('icc_profile'))
I hope this will help others as well.
The difference is that the initial image (on the left in the diagram) has an attached ICC profile whereas the second one (on the right) does not.
I obtained the above image by running the ImageMagick utility called identify like this:
identify -verbose first.jpg > 1.txt
identify -verbose second.jpg > 2.txt
Then I ran the brilliant opendiff tool (which is part of macOS) like this:
opendiff [12].txt
You can extract the ICC profile from the first image also with ImageMagick like this:
convert first.jpg profile.icc
Your first input image has some icc-Profile associated in the meta-data, which is an optional attribute and most devices may not inject it in the first place. The ICC profile basically performs a sort of color correction, and the correction coefficients are calculated for each unique device during calibration.
Modern Web Browsers, Image Viewing utilities mainly take into account this ICC profile information before rendering the image onto the screen, that is the reason why there is a diff in both the images.
But Unfortunately OpenCV doesn't reads the ICC config from the meta data of the image to perform any color correction.

Python - detect elements of a region

I have an array made of 1 and 0 (image below), and I am working on a Python script that detects the borders of the central region (the big white blob) and marks all the internal points as 1. How would you do it?
I wrote a piece of code that does repeated connectivity search, but this doesn't seem the way to go - the region changes shape and new areas are added.
as I can't put a comment i put it here.
I had a problem close to yours: I wanted to select several holes and then calculate the area, the roundness...
What I did was to use the java implementation of python (jython) by which I could use a library called imageJ which is dedicated to image processing (all is include in Fiji). Navigating in the library is a bit fastidiuous but it is powerfull one
Here is the wand tool: http://rsbweb.nih.gov/ij/developer/api/ij/gui/Wand.html
Have a look here for "How getting pixels of a ROi" : http://fiji.sc/Introduction_into_Developing_Plugins#ImageJ.27s_API

Python Targeting System

I am working on a project where I need to program a Raspberry Pi to grab an image from a webcam, search that image for a box and identify what box it is by it's size ratio. The boxes will be a unique color to the rest of the environment. It would also be good to identify the distance from the box and angle to the box.
Everything I've seen seems to indicate that this should be possible, but after several days of searching I have yet to find anything that really helps me to do this. This project is my first experience using Python, so I'm pretty newbish. Any help even with how to do little portions of this would be greatly appreciated.
Here's my working code so far. It's not much, all it does is grab an image from a webcam :/
import imgproc
from img imgproc *
camera = Camera(160, 120)
viewer = Viewer(160, 120)
n = 1
while (n > 0):
img = camera.grabImage()
viewer.displayImage(img)
This is not a complete solution, but some good ideas on how to get started :)
First off, there are Python bindings for OpenCV, an open source free computer vision library originally written in C: http://opencv.willowgarage.com/documentation/python/index.html
The first thing you have to do when solving a computer vision problem is pre-process. In particular, knowing that the box is a different colour helps a LOT - it means we can threshold by colour and create an image that is black where the box is not, and white where the box is, using a technique such as in http://aishack.in/tutorials/thresholding/ .
Then, you'd follow a process similar to the Sudoku grabber/solver described in this blog - you do blob extraction ( http://en.wikipedia.org/wiki/Blob_extraction ) then do a hough transform to get lines, and then you can compare the lines' distances to each other to determine the box's ratio. http://aishack.in/tutorials/sudoku-grabber-with-opencv-plot/
Pretty much just read about people's OpenCV Sudoku solvers until you get the gist of how it's done, because there are a lot of good tutorials and it's a simple illustration of how computer vision projects go: https://www.google.com.au/search?q=sudoku+opencv&aq=f&oq=sudoku+opencv&aqs=chrome.0.57j60l3j0l2.1506&sourceid=chrome&ie=UTF-8
You may want to try installing SimpleCV from the github repo. Using SimpleCV you should be able to get the blob's color using the Image.hueDistance command. If you use the findBlobs command to find your boxes each blob should have its aspect ratio as a parameter. We just posted our full PyCon tutorial about SimpleCV here. You can view just the slides here. We've heard that there are some issues installing PyGame (a SimpleCV dependency) on the RaspberryPi. This walk through might address those issues.

Categories

Resources