detect horizontal & vertical straight line or bar with OpenCV - opencv

I intend to use OpenCV Canny & Threshold algorithm to detect the vertical pols and horizontal lines in the vinery farm, however, I can not distinguish between different counters to select the proper zone with drawContours function
my question is what processing stage or parameters should be added to select this specific area in those pictures
I add the Canny & Threshold images as follows

Related

OpenCV: manipulating different images of the same type to all look the same

I have a large set of images which are cellphone photos taken of driver’s licenses (but this could apply to any type of document). They come in all shapes and sizes, meaning, different angles of the camera, different distances from the camera to the driver’s license, different lighting, etc.
Is there any way in OpenCV to identify in each image a known landmark, then crop, resize, rotate each image so that for the final result, I have a set of images that are completely uniform (e.g. driver’s license fills the whole image, they all look the same, aligned the same, etc)?
Thanks!
One approach (using the functionality available in OpenCV) that I can suggest is to:
Train a Haar Cascade Classifier to recognize the landmark (works quite well for logos)
Take a few rotations of the image and look for the logo in each of them. You should find one or more matches, depending on the number of rotations that you use
Perform edge detection and project the edge pixels to the vertical axis. The projection with largest gaps will represent the spacing between text, and lead you to select one image that is closest to the correct orientation
Now you can crop, zoom or un-zoom this image using the logo position using the known properties of a driving license (logo is so many inches from the top left etc.).
Instead of a Haar cascade classifier, you can also match SIFT features of a logo with that of the photo.
I did not post any code or examples because the question is very broad. But you can easily find OpenCV documentation and examples for each of these steps.
Is there any way in OpenCV to
identify in each image a known landmark: there are several ways to do it, see here: https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_feature2d/py_table_of_contents_feature2d/py_table_of_contents_feature2d.html
crop: yes, subset it and don't forget to copyTo Select a subset of a Mat and copy them to create a new mat in C++/Opencv
resize, rotate each image so that for the final result, I have a set
of images that are completely uniform: you should use transformations like shown here: https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_imgproc/py_geometric_transformations/py_geometric_transformations.html
this tutorial should be useful for you: https://www.learnopencv.com/homography-examples-using-opencv-python-c/

Best method to split many images inside one

I want to split many images inside one image.
My method :
1- Quantize image using pyramid segmentation.
2- Extract contour from image.
3- Accumulate horizontal & vertical edges.
4- Compute the intersection of the horizontal & vertical lines.
What is your suggestion for this problem?
Please refer to the here to see sample images.
I assume the number and size of the images is variable (if they aren't, then you can easily cut at known distances)
Since the joint between different images is going to generate contrasts, you can use canny plus standard line detection. You can find a good tutorial here . Also check documentation of HoughLines & HoughLinesP.
After detecting the lines, you can discard all the non-horizontal and non-vertical ones. Then, you can find positions and distances between horizontal and vertical lines in order to compute the sub-images boundaries.

How to extract and locate the specific region of image by using OpenCV?

I am a newbie to OpenCV. I would like to work on a small project for tracking the rotation speed of a gear (by using webcam). However, until now, I have no idea how to work on this.
The posted image shows a machine which contains two 'big' gears. What I am interested in the gear only on left hand side (the red line as I highlighted).
Link
My plan is:
Extract the Interested gear region .
Mask all unrelated region. So, the masked image shows the left gear only (ROI).
.....
The problem is, how can I locate/extract/mask the ROI and mask?.I go through some example about cvMatchTemplate(), but it doesn't support rotations and scalings. Due to using webcam, the captured image may scaled or rotated. cvfindcontour() will extract all contours in the image rather then ROI.
If you previously know the gear you can use a picture of it to extract keypoints with SIFT, SURF, FAST or any corner detection algorithm. Then do as follows:
1- Apply FAST on every frame to detect keypoints.
2- Extract SIFT descriptors from those keypoints
3- Match detected points in the scene with your previously extracted points from the image. You can use FLANN matcher for this.
4- Those matches will define a region in the scene containing the gear you are looking for.
This is not trivial so you will need to look for information in OpenCV documentation for using all these functions.

Remove high frequency vertical shear noise from image

I have a some scanned images, where the scanner appears to have introduced a certain kind of noise that I've not encountered before. I would like to find a way to remove it automatically. The noise looks like high frequency vertical shear. In other words, a horizontal line that should look like ------------ shows up as /\/\/\/\/\/\/\/\/\, where the amplitude and frequency of the shear seem pretty regular.
Can someone suggest a way of doing the following steps?
Given an image, identify the frequency and amplitude of the shear noise. One can assume that it is always vertical and the characteristic frequency is higher than other frequencies that naturally appear in the image.
Given the above parameters, apply an opposite, vertical, periodic shear to the image to cancel this noise.
It would also be helpful to know how these could be implemented using the tools implemented by a freely available image processing package. (Netpbm, ImageMagick, Gimp, some Python library are some examples.)
Update: Here's a sample from an image with this kind of distortion. Actually, this sample shows that the shear amplitude need not be uniform throughout the image. :-(
The original images are higher resolution (600 dpi).
My solution to the problem would be to convert the image to frequency domain using FFT. The result will be two matrices: the image signal amplitude and the image signal phase. These two matrices should have the same dimensions of the input image.
Now, you should use the amplitude matrix to detect a spike in the area tha corresponds to the noise frequency. Note that the top left of this corner of this matrix should correspond to low frequency components and bottom right to high frequencies.
After you have indentified the spike, you should set the corresponding coefficients (amplitude matrix entries) to zero. After you apply the inverse FFT you should get the input image without the noise.
Please provide an example image for a more concrete (a practical) solution to your problem.
You could use a Hough fit or RANSAC to fit lines first. For Hough to work you may need to "smear" the points using Gaussian blur or morphological dilation so that you get more hits for a given (rho, theta) line in parameter space.
Once you have line fits, you can determine the relative distance of the original points to each line. From that spatial information you can use FFT to find help find a "best fit" spatial frequency and then shift pixels up/down accordingly.
As a first take, you might even skip FFT and use more of a brute force method:
Find the best fit lines using Hough or RANSAC.
Determine the orientation of the lines.
Sampling perpendicular to the (nominally) horizontal lines, find the points along that column with respect to the closest best fit lines.
If the points along one sample are on average a distance +N away from their best fit lines, shift all the pixels in that column (or along that perpendicular sample) by -N.
This sort of technique should work if the shear is consistent along a vertical sample, but not necessarily from left to right. If the shear is always exactly vertical, then finding horizontal lines should be relatively easy.
Judging from your sample image, it looks as though the shear may be consistent across a horizontal line segment between a 3-way or 4-way intersection with a nominally vertical line segment. You could use corner detectors or other methods to find these intersections to limit the extent over which a pixel shifting operation takes place.
A technique I posted here is another way to find horizontal stretches of dark pixels in case they don't fall on a line:
Is there an efficient algorithm for segmentation of handwritten text?
All that aside, is there a chance you could have the scanner fixed?

Correlating a vector with edges in an image

I'm trying to implement user-assisted edge detection using OpenCV.
Assume you have an image in which we need to find a polygonal shape. For the sake of discussion, let's say we need to find the top of a rectangular table in a picture. The user will click on the four corners of the table to help us narrow things down. Connecting those four points gives us a polygon, or four vectors.
But the user is not very accurate when clicking on those corners. So I'd like to use edge information from the image to increase the accuracy.
I'm using a Canny edge detector with a fairly high treshold to determine important edges in my image. (more precisely, I'm scaling down, blurring, converting to grayscale, then run Canny). How can I compute whether a vector aligns with an edge in my image? If I have a way to compute "alignment", my overal algorithm comes down to perturbating the location of the four edge points, computing the total "alignment" of my polygon with the edges in the image, until I find an optimum.
What is a good way to define and compute this "alignment" metric?
You may want to try to use FindContours to detect your table or any other contour. Then build a contour also from the user input points. After this you can read about Contour Moments by which you can compare contours. You can compare all the contours from the image with the one built from the user points and then select the closest match.

Resources