I am developing an app for Android and i have this issue - after i have taken a picture with the camera, i need to crop it. But the coordinates for the rectangle i have dragged over the capturing area start from the screen's 0,0 coordinates aka touch coordinates do not match actual picture's - if i try to crop the image with these using PIL, i get a partial result.
One possible solution would be to take a partial screenshot with these coordinates and get the cropped picture that way.
I tried to use pyscreenshot, but then i found out that it does not work on Android.
Any ideas how to capture a partial screenshot on Kivy?
Thank you
For possible anyone with the same issue - i did not find any good way to grab a screenshot and crop selected portion out of it. I did, however, solve it this way - i move to a new screen, resize picture to device's screen resolution and from then i can crop it with touch without no issues - i did not have to find a clever way to map screen coordinates with image's. After cropping and saving i resize the image back to a fixed resolution. This is not a elegant solution, but still will serve my purpose.
Thank you anyone who thought along with me.
Related
I am working on a program to crop a image around a rectangle in OpenCV. How could I go about doing this. I also need it to be able to turn multiple rectangles into cropped images.
I've tried using this tutorial: https://www.pyimagesearch.com/2016/02/08/opencv-shape-detection/, but I dont know how to get the borders of the shape and crop around it.
I hope to get an output of multiple images, that have pictures of the contents of the triangle.
Thank you in advance
I have just recently done this for one of my projects, and it worked perfectly.
Here is the technique I use to implement this in Python OpenCV:
Display the image using OpenCV's cv2.imshow() function.
Select 2 points (x, y) on an image. This can be done by capturing mouse click events with OpenCV. One way to do this is to click with your mouse where the first point is, while still clicking move towards the second points, and let go from the mouse click once the cursor is over the correct point. This selects the 2 points for you. In OpenCV, you can do this with cv2.EVENT_LBUTTONDOWN and cv2.EVENT_LBUTTONUP. You can write a function to record the two points using the mouse capture events and pass it to cv2.setMouseCallback().
Once you have your 2 coordinates, you can draw a rectangle using OpenCV's cv2.rectangle() function, where you can pass the image, the 2 points and additional parameters such as the colour of the rectangle to draw.
Once you're happy with those results, you can crop the results using something like this:
image = cv2.imread("path_to_image")
cv2.setMouseCallback("image", your_callback_function)
cropped_img = image[points[0][1]:points[1][1], points[0][0]:points[1][0]]
cv2.imshow("Cropped Image", cropped_img)
cv2.waitKey(0)
Here is one of the results I get on one of my images.
Before (original image):
Region of interest selected with a rectangle drawn around it:
After (cropped image):
I started by following this excellent tutorial on how to implement it before further improving it on my own, so you can get started here: Capturing mouse click events with Python and OpenCV. You should also read the comments at the bottom of the attached tutorial to easily improve the code.
You can get co-ordinates of box using 'BoundedRect' function. Then use slicing operation, to extract required part of image.
So I have quite an interesting image segmentation problem. Here, I have scraped instagram photos which are stacked vertically.
see image here(too long to post): https://imgur.com/a/gPr2J
What I am trying to do is quite simple. I just want to extract each post image from the screenshot, and save it to some directory. I am trying to find ways to make this work, like cropping by pixel color at a certain height but none of it is working perfectly.
Any method that would quickly segment this image. Python BTW.
I think you should start with segmenting each post out. Use the gaps between each post (which are always uniform) to segment each post out.
Then approach capturing the image inside the post - breaking this down into 2 different problems will make your algorithm simpler in my opinion.
I have a few ideas, not entirely sure how will they work for you, but thought they might give you some leads to try out:
1) All these instagram images seems to have a "heart" shaped icon just below the image you want to extract. Maybe figuring out detecting the heart shape might be good idea? Once you have found the "heart" you can look for the image just above it. Since it is a UI, my hope is that all the images that you want to extract will be a fixed number of pixels above the "heart". Moreover, they should also have the same height and width, I think.
2) Another possible idea is to find the edges in the image. Again, the images you want to extract seem to have a strong edge with respect to their background (but so does text and other UI elements). However, these edges should ideally have the largest area (which is also mostly fixed) enclosed between them. So, after finding the edges, you can use the find contours in function in opencv and then filter out the contours which have an area greater than a threshold. Have you tried something like this?
recently I have been playing with the 360 fly HD camera and wondering if Aruco Marker can be detected during real time. The first thing come to my mind is to convert the fisheye image into perspective image first and then perform the detection on the perspective image(I am gonna try it and will update my result here later).
Converting a fisheye image into a panoramic, spherical or perspective projection
Hugin HowTo: Convert 360 Image to Cropped Flat Panoramic Image
I am not an expert in this field. Has anyone done this before? Is this something can be achieved by calibrating the camera differently such as correcting the camera matrix and distortion coefficient matrix?
If I am heading to the wrong direction, please let me know.
I was able to get a better understanding during the process.
First, I want to say that 360(fisheye, spherical, however you call it) image is NOT distorted. I was so tricked by my intuition and thought that the image was distorted based on what it looks like. NO it is not distorted. Please read enter link description here for more information.
Next, I have tried both 360 fly cameras and neither works. Every time I tried to access the camera with opencv, it automatically powers off and switch to storage mode. I guess the 360 dev team purposely implements this switching function to prevent "hacking" of their products. But, I've seen people successfully hacked the 360 fly, it's definitely workable.
At last, I was able to detect Aruco with Ricoh theta V(theta S should also work). It's so developer friendly and I was able to make it run in my first attempt. You just have to select the right camera and let the code run. The only problem is the range, which is expected(about 6ft) and Ricoh camera is kind of expensive($499).
click here to view succesful detection
I'm trying to make a my main window have a background image. The problem I'm running into is that the background is comprised of 2 separate images. the top image is placed in the center above the bottom image. I can't find any references on how to accomplish this. I'm thinking I might be able to utilize these two methods to do it, but I'm not sure if I'm heading in the right direction or not.
QGraphicsScene.BackgroundLayer
QGraphicsScene.ForegroundLayer
I'm using python3 with pyqt5. Any help pointing me in the right direction would be greatly appreciated. I wasn't able to find much of anything on this so far.
Thanks in advance.
-edit: In case there is confusion, I have to use 2 images because the background is generated from 2 pictures that are scraped from the web during run time. Maybe someone knows of a way to dynamically merge the 2 images together with specific x,y coordinates with a library, then just use the new image as a background?
I figured it out. The easiest way to accomplish what I'm trying to do is to make 2 labels. 1 that covers the entirety of the window, and another that covers the area where the second picture is supposed to go. Then use Pixmap on each label to cast an image to each label. Figure out the x,y offset required to line up the inner image, adjust the label placement, done.
Question:
Using graphicsmagick, what is a good way to find the coordinates of a small image inside a bigger image?
Explnation:
To explain further, I have a large screen shot that I am working with and would like to find the pixel coordinates of a known icon that is expected to be found somewhere within the screen shot.
Also, if this is not a good library to be using for this purpose, would love to hear suggestions for alternatives that will preferably be compatible with Python.
Thanks so much!
I use "gm display" to do that.
gm display &
Click on the image. Select Transform, then Crop. Put the cursor at the
top left of the small image. Read the coordinates from the small
information window. Select "dismiss"
Note that this is a manual method, which is OK if you are really "working
with the image" on screen. If you are looking for a batch method, it'll
be a little more complex.