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.
Related
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 months ago.
Improve this question
I have almost 200 images (.png files) that I want to assemble together into one PNG file. All the image files have the same dimensions (705 x 1000).
I want to make 20 rows of 10 images each row, with 10 pixels horizontally between each image and 10 pixels between each row.
How can I do this programmatically? Can this be done with Python? Can I avoid having to do this manually using a word-processing or other other office style program?
I did some Googling and found my answer.
The Pillow Python package is exactly what I was looking for.
It can merge images as such:
from PIL import Image
def merge(im1, im2):
w = im1.size[0] + im2.size[0]
h = max(im1.size[1], im2.size[1])
im = Image.new("RGBA", (w, h))
im.paste(im1)
im.paste(im2, (im1.size[0], 0))
return im
(taken from Official Pillow docs)
This is enough to get me started!
With ImageMagick in Terminal, using:
magick montage *.png -tile 10x20 -geometry +10+10 result.png
If Python is a hard requirement, which doesn't seem to be the case from your question, you can use wand which is a Python binding to ImageMagick.
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.
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
I am trying to extract handwritten text from:
using https://cloud.google.com/vision/docs/handwriting
Without using any third party technology, is there any option in Google vision API to remove vertical and horizontal lines from the image before extracting the text?
Hahaha I literally did the exact same thing like 2 months ago.
No, the Vision API can't do this.
Here's how I did it:
1) create an image object with the Python PILLOW library.
2) Get the matrix representation of the image.
3) binarise the matrix.
4) Loop through it line by line and row by row. When you encounter a black pixel, start a counter. If you encounter a white pixel, reset the counter. If the counter goes higher than some high number, conclude that it is a line.
5) Change the black pixels in the line to white pixels.
6) Use Pillow to get a PNG back again.
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)
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 6 years ago.
Improve this question
I am working on a project on virtual keyboard.
Using the webcam, I want to detect black keys on a projected keyboard on a wall (projected using a projector).
The keyboard has white background with black keys -
As it is projected, there will be some continuous movement of the keyboard, although little.
From my understanding, I will have to detect this white rectangle, then further detect the black keys in it for every frame.
Can you please tell if this is correct?
How do I go about it using Python and OpenCV?
Thank you!
I imagine that you whant to create a functioning projected keyboard. If it is the case, you effectively whant to first map the position of the projected keys in the webcam image. Then detect a "press" position in this same image. By comparing the two information you will be allowed to "detect" a "keypress". first at all, since detecting the "press" position is the harder, what do you imagine to do that ? (I will then tell you what can be done to map the keys positions)(this is a seriously advanced project dude)