Extract object and save it as an image.png using c++ [closed] - python

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
Actually I work on a car detection project at real time, when I launch the camera I want to make a screenshot (.png) for any car and save it in a path, which means i need a function in opencv that does the screenshot of just a car detected (not all windows).
Suppose you have the following image:
Now i want to extract to individual images each of the independent cars, like this for example:
And save in path/image_date.png.
Thanks in advance.

Given an image and a bounding box that is determined by your car detector:
cv::Mat image = …;
cv::Rect roi = …; // roi stands for "region of interest"
cv::Mat output = image(roi); // slice the car rectangle out of the image
cv::imwrite("car.png", output);
Note that this operator() will reference the original image data, no data copy will be made. So this is a very efficient way of working on a specific region of interest.
How to best detect the cars in an image in the first place, is too broad for a SO question.

Related

Finding the top edge of a disk [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 days ago.
Improve this question
I have a stock of photos, of a spinning disk of varying angles. I wish to find the edge of the top of the disk. The top is colored in a distinct black color in comparison to the rest of the photo.
A
B
I first tried using canny edge detection which does a decent job, but also identifies the bottom half of the disk, which I wish to avoid.
Next idea was to use the distinct black color- perhaps by dividing the photo into domains characterized by colors\intensities- and by choosing the largest domain\most black domain or some other parameter, perhaps to isolate that black circle, and only then to use canny edge detector.
Is there any existing function that can divide a greyscale image into domains? Transferring from matlab to python, so I'm new to it's syntax and functions.
Thanks
The Canny disaster goes on !
People playing with image processing keep willing to rely on edge detection when they have beautifully segmenting scenes. With a careful selection of a binarization threshold, you can extract the ellipse as a single piece.

Is there a way to find the speed from analog speedometer? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I have an analog speedometer image, with the needle pointing to the current speed. I am trying to find a way to get the speed that the needle is pointing out to. I tried using HoughCircles() from OpenCV, but it is throwing an error as the image contains only speedometer and which is a semi-circle. Any resources to help me move forward will be appreciated.
Assuming the needle will have a different colour to the rest of the speedometer OR its size is distinctly larger than the rest of the elements on the speedometer (which is often the case), I'll do something like below.
Convert the image to grayscale.
Apply colour thresholding (or size-based thresholding) to detect the pixel area representing the needle.
Use HoughLines() or HoughLinesP() functions in OpenCV to fit a line to the shape you detected in Step 2.
Now it's a matter of measuring the angle of the line you generated in Step 3 (example provided here: How can I determine the angle a line found by HoughLines function using OpenCV?)
You can then map the angle of the line to the speed through a simple equation (Will need to see an image of the speedometer to generate this).
let me know how it went.

Want to get a part of a image [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am making google's t-rex runner game. So I got a .png file which contains all the fonts, picuters of the t-rex, etc. So I am now having problem in getting a part of the image. Here is the image:
Is there anyway in which I can get a part of the image. I am using python, pygame.
Assuming you know what a Rect and Surface is, here is a way to do it:
def image_at(png, rectangle): # rectangle would be the section you want in the png
rect = pygame.Rect(rectangle)
image = pygame.Surface(rect.size)
image.blit(png, (0, 0), rect)
return image
(inspired by https://www.pygame.org/wiki/Spritesheet which could be exactly what you were looking for)
Basically you create a surface with the dimensions of your desired section of the png, they you draw (blit) the whole png on your created surface, and that will show only the part you selected throught your rectangle.

Removing lower pixel valued connected components from image [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
Is there any way to remove the lower pixel valued connected components from the below picture? Like I want the horizontal and vertical lines and small already printed texts removed except the handwritten text.
I want the handwritten text to be extracted like in this image.
Is there any specific library I can use for this purpose?
I was trying Python OpenCV's library to threshold the noise pixels out of the image but that is not giving perfect result.
The image I'm getting after using threshold is this.
If I increase the threshold then it is removing pixels from the handwritten text itself.
Combine the OpenCV methods erode and dilate. They are able to first (erode) get rid of noise and then amplify the main signale (dilate).
You can develop an algorithm based "connected component analysis" to remove undesired connected components. You just need to detect connected components and remove the small ones to extract the desired ones. A case study about it can be found in here and can be helpful for you to develop the solution for your case.

Create a rectangle around a binary image mask [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
From a given image i'm able to create a binary mask that detect certain objects, how i can draw multiple rectangles a round those detected objects so that i're draw it to the original image also if it possible to obtain the corrdinates of those rectangle so i can plot them in the original image
As you haven't provide code, I will answer without code as well.
You should use findCountours. There is an opencv tutorial that helps you in this exact task: https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_imgproc/py_contours/py_contour_features/py_contour_features.html
cv2.findContours returns an array of contours, for each contour in contour you will need to:
x,y,w,h = cv2.boundingRect(cnt)
img = cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),2)

Categories

Resources