This question already has answers here:
Incorrect rectangle location in matplotlib
(2 answers)
Clickable matrix image with python and matplotlib [duplicate]
Closed 8 years ago.
I saved multiple matrix images using
imshow
savefig
to disk and now I would like to detect the offset between the picture frame and the first pixel.
My problem is that I have to use labels around the plot area which moves the real data view around based on the label text length -> offsets become arbitrary.
Hence, I would like to automatically detect the offset between the upper left corner in the image and the upper left corner of the active plot area + the width & height used to plot one matrix entry.
I guess the parameter must be somewhere buried in the
axes.transData
axes.transAxes
properties (?), but I seem not to find it.
Thanks,
EL
Related
This question already has answers here:
OpenCV Python: Draw minAreaRect ( RotatedRect not implemented)
(5 answers)
Find Rotated Rectangle in OpenCV Python
(1 answer)
Closed 2 years ago.
I been messing with Python and OpenCV on some images, and kind of got the result I want. Here is an example of the output image.
So the important part is opencv has draw red rectangles around the objects it has identified (I don't want to share what the original image was so yes those gray patches are all the remain after running a lot of functions on the image).
Now what I want to do is expand the rectangles (there are 2 here, but 3 or 4 are also possible) so they are as large as possible without touching. I just can't seem to come up with any kind of algorithm to do that. Any suggestions?
This question already has answers here:
Intersection and difference of two rectangles
(3 answers)
Closed 2 years ago.
I am a noob and trying to learn OpenCV, I am working on a mini project which triggers certain functions if a person is detected in a specific area of the frame marked with a bounding box, can somebody guide how can I check whether a bounding box [ i.e detected object/person ] is overlapping with an already drawn bounding box[ i.e bounding box specified on a certain position of screen ] are overlapping?
In OpenCV python you'll have to implement this by hand. Check this for an implementation example.
This question already has answers here:
Split text lines in scanned document
(2 answers)
Closed 4 years ago.
I have generated the edges using Canny edge detector now want to crop source image by those edges.
Is there any way to get.
Left and Top Most 255 pixel location of image.
Right and Top Most 255 pixel location of image.
Left and Bottom Most 255 pixel location of image.
Right and Bottom Most 255 pixel location of image.
And crop that image based on that location.
Using open cv or any other library using python.
There may be better solutions but I think you can implement an algorithm.
Start by drawing a square that FULLY captures the child set of pixels. Then, slowly bringing in the sides one at a time until they encounter a 255 pixel. Once you've fully pulled in all 4 sides, you will have your desired area to crop.
You could also use four simple (one-liner) For loops to check for "first white pixel". Since pixels x-pos starts at top/left, Using x++ to check forward and x-- to check backwards (from right-side).
This question already has an answer here:
matplotlib: add circle to plot
(1 answer)
Closed 5 years ago.
I have an image as follows:
The image is generated in Python. I want to further plot a curve on top of the image, which encloses the white region. I have already got the pixel indices for the region border. I know in Matlab, e.g., it can be simply done by :
hold on
plot(x,y,'r-') %x and y are the indices of boundary pixels.
The resultant image should be like this:
How can I do that contour on top of the image in Python, not by cv2.drawContours? Anyone can help me with the problem?
You can use the Pillow library for it. Without going into the whole solution, there's a good example in their tutorial on how to read an image an do some postscript drawing on top of it: https://pillow.readthedocs.io/en/4.1.x/handbook/tutorial.html#drawing-postscript
You pretty much only need to change the rectangle to a circle instead.
The cut down example is:
from PIL import Image
from PIL import PSDraw
im = Image.open("lena.ppm")
box = (1*72, 2*72, 7*72, 10*72) # in points
ps = PSDraw.PSDraw() # default is sys.stdout
ps.begin_document(title)
# draw the image (75 dpi)
ps.image(box, im, 75)
ps.rectangle(box)
ps.end_document()
PS. I'm assuming that by "I have an image as follows:" you mean, you have an image file and want to process that, not that you're generating that graph in python already. If you're using something like matplotlib to generate it in the first place, you can add it there instead.
If you're already doing it in matplotlib, then the question is likely a duplicate of matplotlib: add circle to plot
This question already has answers here:
how to remove straight lines or non-curvical lines in a canny image
(2 answers)
Closed 6 years ago.
I have the following image. My task is to examine the shape of worms (enclosed in rectangles) and classify them as dead/alive - the ones that are rod-like (straight) are dead and the curved ones are alive.
I have used adaptive thresholding on the source image, drawn the contours and bounding rectangles using OpenCV 3.1.0 in Python 2.7.1 . What would be the simplest and perhaps an efficient way to achieve the above aim.
(isConvex() certainly doesn't work :p)
One approach would be to compare the length of the contour (or worm) to the diagonal distance of the bounding box (upper left corner to bottom right corner distance). The straight ones will have a length closer to this distance than the curvy ones will.