so im trying to extract data from invoices for that im using abby cloud ocr. im got the output as xml file now what i want to do is look for a text and take its rectangle cordinates and then look for closest rectangle and take its value
to do that i need the rectangle coordinates well the xml file actually return cordinates but i cant understand it
ill show u an example of the xml output (ill replace uneeded text with '....')
<line baseline="2062" l="2037" t="2033" r="2206" b="2064">....</line>
<line baseline="2101" l="295" t="2070" r="588" b="2097">....</line>
these are too different rectangles anyway i went to see the documentation and this is what is says
baseline — the distance from the base line to the top edge of the page
l — the coordinate of the left border of the surrounding rectangle,
t — the coordinate of the top border of the surrounding rectangle
r — the coordinate of the right border of the surrounding rectangle
b — the coordinate of the bottom border of the surrounding rectangle
what coordinate of the left border of the surrounding rectangle mean ?
isnt the rectangle coordinates on this format [[x1,y1],[x2,y2],[x3,y3],[x4,y4]]?
can you explain to me what they mean by these coordinates or how can i use it ??
I'm trying to get a box around a segmented object on the edge of the image, that is, there is no contour around the segmentation because the object is only partially inside the image region.
I use skimage.segmentation, find_boundaries, clear_border, and regioprops. However, regionprops does not provide those edge cases
segments_fz = felzenszwalb(cv2.cvtColor(image, cv2.COLOR_BGR2RGB), scale=300, sigma=0.5, min_size=50)
cleared = clear_border(segments_fz)
label_image = label(cleared)
regionprops(label_image)
A box around segmented object near the limit of the image region.
You shouldn't use clear_border. Then the objects on the border will be treated like any other. The bbox property should give you a bounding box for your object of interest, while find_boundaries and mark_boundaries will let you get or visualise the boundaries between segments.
I am working on a game in pygame/python, and I am wondering who has the know how to show me to turn an image into a map.
The idea is simple. The image is colored by tile type. When the program loads the image, I want the color (example) #ff13ae to be matched to a certain grass tile, and the color (example) #ff13bd to a different tile. Now, I know that I may very well have to convert from hexcodes to rgb, but that is trivial. I just want to know the way I would go about this, mainly because all my other games don't do anything of this sort.
Use pygame.PixelArray:
The PixelArray wraps a Surface and provides direct access to the surface's pixels.
[...]
pxarray = pygame.PixelArray(surface)
# Check, if the first pixel at the topleft corner is blue
if pxarray[0, 0] == surface.map_rgb((0, 0, 255)):
...
I have code that takes an image from the webcam, scans it for QR codes using zBar and returns the value of the code and an image with the QR code highlighted (based off http://sourceforge.net/p/qrtracker/wiki/Home/). How can I also make it tell me the size of the code (as a pixel value or % of the screen)?
Additional question: is there a way to detect how skewed it is (e.g rotation in Z about the Y-axis)?
Regarding the size of Code
zBar provides a method to do this in terms of pixel values (Once you know the size in pixel values, you can find it in %)
I would like to extend the code here: http://sourceforge.net/apps/mediawiki/zbar/index.php?title=HOWTO:_Scan_images_using_the_API
Above code finds a QR code in an image, prints its data etc. Now checking last few lines of code:
import math
scanner.scan(image)
[a,b,c,d] = x.location # it returns the four corners of the QR code in an order
w = math.sqrt((a[0]-b[0])**2 + (a[1]-b[1])**2) # Just distance between two points
h = math.sqrt((b[0]-c[0])**2 + (b[1]-c[1])**2)
Area = w*h
Skewness of QRCode
I think you want to transform it into a pre-defined shape (like square, rectangle, etc). If so, you can define corners of a pre-defined shape, say ((100,100), (300,100),(300,300),(100,300)). Then find the perspective transform and apply the transformation if you would like. An example in OpenCV is provided here: http://docs.opencv.org/trunk/doc/py_tutorials/py_imgproc/py_geometric_transformations/py_geometric_transformations.html#perspective-transformation
Is there a way to set individual pixel values for image data in Pyglet?
I guess it can also be done by setting the OpenGL rendering mode to points, so if someone has insight on this, please share it as well.
The solution which ended up appearing the most suitable to me is to use the ImageData class, which comes with every AbstractImage subclass.
ImageData array Retrieval
The ImageData class represents an image as an array of bytes, or more precisely a String of which each character represents a coordinate in the desired color space.
To obtain that byte representation of a given image, you would call
image_data = image.get_image_data()
width = image_data.width
data = image_data.get_data('RGB', 3*width)
The second parameter we are passing to get_data here is the number of bytes we are expecting to get for each row of the image. Because we want to have all of the components R, G and B for each and every pixel, we would like to have 3 times the width of the image. If we would only be interested in, say, the intensity for each pixel, we would pass the parameters ('I', image.width). Here's some official documentation.
To get the values only for the very pixel you are interested in, e.g. the one at (x,y), you might want to do sth like this:
pos = (width*y + x) * 3
rgb = map(ord, data[pos:pos+3])
Instead of retrieving the ImageData for the entire image and picking the desired pixel's values afterwards, you can also call get_image_data() for a certain region, i.e. 1x1 pixel at the desired position:
image_data = image.get_region(x,y,1,1).get_image_data()
That's the way how it is done is this google groups post, where you can also find the useful information that it seems to be more efficient to get your image data as RGBA instead of RGB.
Setting individual pixels
Now, to finally answer question, there is also a setter method for the image byte data of ImageData, set_data, which works just the other way around.
image_data.set_data('RGB', image.width*3, data)
This probably works for regions, too, but I haven't tried. In case you want to set byte data that you have stored in an integer array, pass ''.join(map(chr, data)). I don't know if there's a way to set numerical values.
Hope this helps anybody stumbling upon this quite old question, which yet happens to be a prominent google result for certain search terms.
The following is purely from an OpenGL standpoint, I don't know of any pyglet tricks for this.
There is always glDrawPixels, or you could use an OpenGL texture that is the same resolution as your window (best if you can use non power of two texture sizes) and then map that texture on to a quad that takes up the entire window.
The latter I think is the fastest solution for when you don't have to change pixels on every refresh because all the data is already on the card.
You can keep a "local" (in cpu memory) cache of the texture data for easy modification and re-uploading. Or, for bonus points, you can modify the texture data directly via OpenCL ;)
You can set up a batch using batch = pyglet.graphics.Batch() and then add vertices to the batch by calling batch.add(npts, gl_type, group, pixel_data, color_data), where npts is the integer specifying how many points you will be listing as tuples in pixel_data, and gl_type in your case is pyglet.gl.GL_POINTS. batch.draw() then draws all the vertices that you've added to your batch. The example below draws a line by adding vertices (i.e. GL_POINTS) to the batch at each call of on_draw():
import pyglet
COLOR = (0,255,0)
FRAMERATE = 1.0/60
(x,y) = (50,50)
window = pyglet.window.Window()
batch = pyglet.graphics.Batch()
# the vertex_list will keep a handle on all the vertices we add to the batch
vertex_list = [batch.add(1, pyglet.gl.GL_POINTS, None,('v2i', (x,y)),('c3B', COLOR))]
#window.event
def on_draw():
window.clear()
# the next vertex will use the vertices of the vertex currently at the end of the current vertex_list
(x,y) = vertex_list[-1].vertices
vertex_list.append(batch.add(1, pyglet.gl.GL_POINTS, None,('v2i', (x+1,y+1)),('c3B', COLOR)))
batch.draw()
pyglet.clock.schedule_interval(lambda dt: None, FRAMERATE)
pyglet.app.run()
There is probably a more efficient way of drawing lines than the way above, but this way gives you a good idea of how the batch works. Check out the docs for more here.