I need to find the coordinates of the largest empty rectangle in a PNG image. The rectangle should consist of light colors (if that is too difficult, white pixels only are fine) and should be axis-oriented.
I am new to computer vision and I found out about OpenCV, I am currently using the python interface to it and started tackling this problem with the SimpleBlobDetector interface, but it gives me only the center of the Blob with a certain radius.
Can anyone point me in the right direction for this?
EDIT: I need to do this with a regular colored PNG image, not a binary matrix
You can use a contour extractor, with the given point list you can check the size of the rectangle by checking the sizes of the lists, assuming that all the rectangles are parallel to the cardinal axis. If not you need to compute the distance of a pixel and the next for all the pixels in the contour list by using the x and y coordinates on each.
Related
I have a rotated object (clips for wires for a motherboard)
which I have then used Thresholding and findContours to get the contour of the region of interest (in green). It is an irregular shape which may not always be a rectangle. I know the coordinates I was to place the center of this image on within the section of the motherboard
but do not know how to do this without using bg[y:y+obj_h, x:x+obj_w] = obj, which would assume rectangular shape and would introduce a large noise perimeter surrounding the rotated image. I have tried using transparency around the object, which does not work with cv2. The target goal is this
Any help would be appreciated.
I'm using the google maps static api to get top view satellite images of objects of which I have the surface coordinates (LoD1 / LoD2).
the points are always slightly off, I think this is due to a small tilt in the satellite image itself (is it a correct assumption?).
For example in this image I have the building shape, but the points are slightly off. Is there a way to correct this for all objects?
The red markers are the standard google-maps api pointers, the center of the original image (here it is cropped) is the center of the building, and the white line is a cv2.polyline implementation of the object shape.
Just shifting by n pixels will not help since the offset depends on the angle between the satellite and object and the shape of that object.
I am using the pyproj library to transform the coordinates, and then convert the coordinates to pixel values (by setting the center point as the center pixel value, and having the difference in the coordinate space, one can calculate the edge-points pixel values too).
So - the good news is that there is no need to "correct" this for all objects, because there is no way to do that without using 3d models & textures.
Google (or most map platforms for that matter) don't actually use satellite images, they use aeroplane images. The planes don't fly directly over the top of every building (imagine how tight/redundant their flight path would be if they did!).
Instead, the plane will take an image from some kind of angle, and then, through the wonders of photogrammetric processing, the images are all corrected and ortho-rectified so the ground surface is in the right place everywhere.
What can't (and shouldn't) be corrected in a 2d image is the location of objects above ground height. Like the roof in your image. For a more extreme example, just look at a skyscraper, and you'll realise you can't ever get the pixels correct above the ground:
https://goo.gl/maps/4tLSrd7yXQYWZPTy7
I am trying to transform a picture with OpenCV in python.
Therefore I have points in a grid placed on the image that I can also move.
I then split each grid rectangle into two triangles and I have their coordinates:
where they were at the beginning and
where they are after i moved some points around
Now I want to transform the image so it fits the new mesh but without seeing lines on the edges of the triangles or image pieces getting ripped by transforming differently.
Help!
I have a Python script that uses PIL and the HSV color space to detect all the red objects in an image.
It can output a list of red pixels in the image that looks like [(x,y),(x,y),(x,y),
etc.]
Using this list, I can find the center of all red pixels with [sum(list(x))/len(list(x)) for x in zip(*list)]
What I'd like to do is find the respective centers of all red objects (Both the center of the trash can AND the center of the folder). To do this, I want an efficient way to divide the list into multiple lists, one for each solid object. Then, I can take these lists and exclude the ones with fewer than 20 pixels to account for disconnected specks of color.
How can I best separate lists of (x, y) coordinates into multiple lists of connected pixels?
NOTE: I do not have scipy, OpenCV, or scikit-image available. I have PIL and Numpy
I ended up just using breadth-first search to flood-fill the area. In this case, depth-first search would've worked just as well, though.
I'm currently involved in a hardware project where I am mapping triangular shaped LED to traditional bitmap images. I'd like to overlay a triangle vector onto an image and get the average pixel data within the bounds of that vector. However, I'm unfamiliar with the math needed to calculate this. Does anyone have an algorithm or a link that could send me in the right direction? (I tagged this as Python, which is preferred, but I'd be happy with the general algorithm!)
I've created a basic image of what I'm trying to capture here: http://imgur.com/Isjip.gif
Will this work: http://www.blackpawn.com/texts/pointinpoly/default.html ?
You can do line rasterization on the lineparts to determine for each pixel at each horizontal scanline lie within your triangle. Sum and divide their RGB values to get the average.