I would like some help explaining how to use the opencv group rectangles function in python SHOWN HERE.
I am running 2 haar cascades to detect objects in the image, but now I would like to merge the rectangles together. I am guessing thats what the groupRectangles is used for.
cv2.groupRectangles(rectList, groupThreshold, eps, weights, levelWeights)
I am assuming that rectList is the vector returned by cv2.cascade.detectMultiScale()?
Also I am not sure what the weights, and levelWeights are or what tehy are used for and would appreciate it if anyone could explain that, or show me where I can find out about it as i cant
find it in the documentation.
Thanks for any help :-)
Maybe something changed in the meantime, but following the link you provided the definition is:
cv2.groupRectangles(rectList, groupThreshold[, eps]) → rectList, weights
So yes, rectList is a list of rectangles, in your case you would use the one returned by cv2.cascade.detectMultiScale(). While the optional eps controls, how similar (in terms of position and size) two rectangles need to be to be merged, the groupThreshold indicates how many rectangles at least need to be merged into one in order the keep the merged one.
You will be returned the new list of rectangles and a weight for every rectangle, I assume the weight reflects how many rectangles where merged and how similar they were.
Related
Say that we have the following polygon:
Now I'm looking for one of two results, where either problem will help me continue my current tasks. So I would just need one of the following two problems to be solved:
Calculate the center line of the polygon:
Now I have looked at this post already, however the library used is outdated and I haven't managed to make it work properly.
Split the polygon into separate rectangles that fill up the entire polygon, non-overlapping.
Note that this is a very simple example of the kind of polygon whose solution I would need. I would need the exact same for a much more complex polygon, say the following:
So as I said, I need one of these 2 problems solved. Problem 1 is just a way to generate a solution for problem 2. Having the polygon split into distinct rectangles is the final goal.
Are there any resources that could help with this?
(Also pardon my paint-skills)
I have a set of polygons and they can overlap with each other, like this:
I want to modify them in such a way that they don't overlap and the resulting surface area stays the same. Something like this:
It is okay if the shape or the position changes. The main thing is that they should not overlap with each other and the area should not change much (I know the area changed a little in the second image but I drew it manually thus let's just assume that the areas did not change).
I am trying to do it programmatically with the help of Python. Basically I stored polygons in a PostGIS database and with the help of a script I want to retrieve them and modify them.
I am very new to GIS and thus this seems like a difficult task.
What is the correct way of doing it? Is there an algorithm that solves this kind of problems?
Take a look at ST_buffer and try passing a signed float as the second argument (degrees to reduce radius by)
SELECT buffer(the_geom,-0.01) as geom
Be careful with negative buffers as you could run into issues if the buffer size exceeds the radius, see here.
Here is what I did:
Iterated over all the polygons and found overlapping polygons. Then, I moved the polygon in different directions and found the best moving direction by calculating the minimum resulting overlapping area. Then I simply moved the polygon in that best direction until there is no overlapping area.
I am generating images (thumbnails) from a video every 3 seconds. Now I need to discard/remove all the similar images. Is there a way I could this?
I generate thumbnails using FFMPEG. I read about various image-diff solutions like given in this SO post, but I do not want to do this manually. How and what parameters should be considered that could tell if a particular image is similar to other images present.
You can calculate the Structural Similarity Index between images and based on the score keep or discard an image. There are other measures you can use, but basically a method that returns a score. Try PIL or OpenCV
https://pillow.readthedocs.io/en/3.1.x/reference/ImageChops.html?highlight=difference
https://www.pyimagesearch.com/2017/06/19/image-difference-with-opencv-and-python/
I dont have enough reputation to comment my idea on your problem, so i will just go ahead and post it as an answer in hope of helping you.
I am quite confused about the term "similar" but since you are reffering on video frames i am going to assume that you want to avoid having "similar" frames that have been captured because of poor camera movement. If that's the case you might want to consider using salient point descriptors.
To be more specific you can detect salient points (using for instance Harris) and then use a point descriptor algorithm (such as SURF) and discard the frames that have been found to have "too many" similar points with a pre-selected frame.
Keep in mind that in order for the above process to be successful, the frames must be as sharp as possible, i guess you don't want to extract as a thubnail a blurred frame anyway. So applying a blurred images detection might be useful in your case.
I have some data about a set of coordinates, like {(x=1, y=2), (x=3, y=4), ...}. I projected these coordinates on the picture. Then I would like to count these point in different position. My idea is below
First, separate the picture from several pixel parts based on 10 pixels.
Second, count the point inside the pixel box.
I am new in these area, and I use python a lot. I think this may be computer graphic problem.
I am not asking for a code solution. I just want to know which libraries or approaches that are related.
Anyone could give me a hint would be highly appreciated. Thanks.
Sure, your approach seems fine. You simply want to count the number of pixels in different image regions that you placed, correct?
I answered a question recently (with Python) that was giving an indication if there was a black pixel inside an image region. It could be easily modified to count pixels instead of simply finding one. Check it out here and modify your question or post a new one if you have code problems working it out.
I have an image find- and "blur-compare"-task. I could not figure out which methods I should use.
The setup is this: A, say, 100x100 box either is mostly filled by an object or not. To the human eye this object is always almost the same, but might change by blur, slight rescaling, tilting 3-dimensionally, moving to the side or up/down by a or two pixel or other very small graphical changes.
What is a simple quick robust and reliable way to check if the transformed object is there or not? Points to python packages as well as code would be nice.
Not sure I entirely understand your question, but I'll give it a shot..
Assuming:
we just want to know if there is some object in a box.
the empty box is always the same
perfect box alignment etc.
You can do this:
subtract the query image from your empty box image.
sum all pixels
if the value is zero the images are identical, therefore no change, so no object.
Obviously there actually is some difference between the box parts of the two images, but the key thing is that the non-object part of the images are as similar as possible for both pictures, if this is the case, then we can use the above method but with a threshold test as the 3rd step. Provided the threshold is set reasonably, it should give a decent prediction of whether the box is empty or not..