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).
Related
First image is the Original image. Second image is the Processed image. The image consists of a test tube containing some amount of precipitate at the bottom. I am trying to crop out only the Precipitate area of the image.
For achieving this, I have tried processing the original image so that the Upper edge of precipitate is detected. I am able to detect the upper edge of precipitate as you can see in the Processed image.
My question is, how do I crop the image from that upper edge to the bottom of test tube using OpenCV (Python) or some other library perhaps ? I am open to ideas and codes that can help. Thanks!
Original image
Processed image
The surface of the precipitate is bright.
This is what you can get by getting the saturation component, applying Gaussian filtering horizontally and binarizing.
Horizontal delimitation of the ROI should not be difficult.
I'm currently working on my first assignment in image processing (using OpenCV in Python). My assignment is to calculate a precise score (to tenths of a point) of one to several shooting holes in an image uploaded by a user. One of the requirements is to transform the uploaded shooting target image to be from "birds-eye view" for further processing. For that I have decided that I need to find center coordinates of numbers (7 & 8) to select them as my 4 quadrilateral.
Unfortunately, there are several limitations that need to be taken into account.
Limitations:
resolution of the processed shooting target image can vary
the image can be taken in different lighting conditions
the image processed by this part of my algorithm will always be taken under an angle (extreme angles will be automatically rejected)
the image can be slightly rotated (+/- 10 degrees)
the shooting target can be just a part of the image
the image can be only of the center black part of the target, meaning the user doesn't have to take a photo of the whole shooting target (but there always has to be the center black part on it)
this algorithm can take a maximum of 2000ms runtime
What I have tried so far:
Template matching
here I quickly realized that it was unusable since the numbers could be slightly rotated and a different scale
Feature matching
I have tried all of the different feature matching types (SIFT, SURF, ORB...)
unfortunately, the numbers do not have that specific set of features so they matched a quite lot of false positives, but I could possibly filter them by adding shape matching, etc..
the biggest blocker was runtime, the runtime of only a single number feature matching took around 5000ms (even after optimizations) (on MacBook PRO 2017)
Optical character recognition
I mostly tried using pytesseract library
even after thresholding the image to inverted binary (so the text of numbers 7 and 8 is black and the background white) it failed to recognize them
I also tried several ways of preprocessing the image and I played a lot with the tesseract config parameter but it didn't seem to help whatsoever
Contour detection
I have easily detected all of the wanted numbers (7 & 8) as single contours but failed to filter out all of the false positives (since the image can be in different resolutions and also there are two types of targets with different sizes of the numbers I couldn't simply threshold the contour by its width, height or area)
After I would detect the numbers as contours I wanted to extract them as some ROI and then I would use OCR on them (but since there were so many false positives this would take a lot of time)
I also tried filtering them by using cv2.matchShapes function on both contours and cropped template / ROI but it seemed really unreliable
Example processed images:
high resolution version here
high resolution version here
high resolution version here
high resolution version here
high resolution version here
high resolution version here
As of right now, I'm lost on how to progress about this. I have tried everything I could think of. I would be immensely happy if any of you image recognition experts gave me any kind of advice or even better a usable code example to help me solve my problem.
Thank you all in advance.
Find the black disk by adaptive binarization and contour (possibly blur to erase the inner features);
Fit an ellipse to the outline, as accurate as possible;
Find at least one edge of the square (Hough lines);
Classify the edge as one of NWSE (according to angle);
Use the ellipse and the line information to reconstruct the perspective transformation (it is an homography);
Apply the inverse homography to straighten the image and obtain the exact target center and axis;
Again by adaptive binarization, find the bullet holes (center/radius);
Rate the holes after their distance to the center, relative to the back disk radius.
If the marking scheme is variable, detect the circles (Hough circles, using the known center, or detect peaks in an oblique profile starting from the center).
If necessary, you could OCR the digits, but it seems that the score is implicitly starting at one in the outer ring.
I'm trying to extract the edge of a drop from the following image which I've first applied cv2.Canny() onto:
I tried using cv2.findContours() (and taking the longest contour found) but this ends up being a closed loop around the drop's 1 pixel edge (shown exaggerated in blue).
Is there a way to extract just a single open edge (as a list of (x, y) points, similar to the structure of a contour returned by findContours()) that goes around the profile of the drop?
Images:
Original Image
After applying Canny
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.
This question already has answers here:
Detect gray things with OpenCV
(2 answers)
Closed 8 years ago.
I am working on a project which involves using a thermal video camera to detect objects of a certain temperature. The output I am receiving from the camera is an image where the pixels of interest (within the specified temperature range) are colored yellow-orange depending on intensity, and all other pixels are grayscale. I have tried using cv2.inRange() to filter for the colored pixels, but results have been spotty, as the pixel colors I have been provided with in the color lookup tables do not match those actually output by the camera.
I figured then that it would be easiest for me to just filter out all grayscale pixels, as then I will be left with only colored pixels (pixels of interest). I have tried looping through each pixel of each frame of the video and checking to see if each channel has the same intensity, but this takes far too long to do. Is there a better way to filter out all grayscale pixels than this?
filter out greyscale or filter in the allowed colors
Idk if the range of colors or range of greyscale is larger but maybe whitelisting instead of blacklisting is helpful here