I want to detect a credit card sized card in image. The card can be any card eg identity card, member card. Currently, I am thinking to use Canny Edge, Hough Line and Hough Circle to detect the card. But the process will be tedious when I want to combine all the information of Hough Line and Hough Circle to locate the card. Some people suggest threshold and findContour but the color of card can be similar to the background which make this method difficult to achieve the desired result. Is there any kernel and method which can help me to detect the card?
I think, your problem is similar to document scanner. You can refer to this link
Find edges in the image using Canny edge detector (lower and higher thresholds can be set as 0.66*meanIntensity and 1.33*meanIntensity) and do a morphological close operation.
Edge image after performing close
Find the contours in the image using findContours
filterout unwanted contours (I used contourArea to filter contours)
using approxPolyDP approximate the contours to 7 or more points. (I used 0.005 * perimeter as the parameter here)
If you want to find accurate edges, fit lines between the points and get the 4 biggest lines.Find their intersection (since the card may or may not contain curved edges)
You'll end up with the card endpoints which can be used further for homography or to determine the region.
vertices of the card
Edit
Edited the answer to include the steps to obtain the vertices of the card and results are updated.
There are two sub-problems here -
Detect rectangular object in the image.
The rectangular object's actual size should be similar to Credit Card.
For first part, you can try out several methods to extract rectangular region in the image and see which suits your need.
This post shows a lot of methods which you can try out.
In my experience edge detection works best in most cases. Try Canny > Contours with Appoximations > Filter out irrelevant contours > Search for rectangles using some shape detection, template matching or any other methods. Even this post does a similar thing to achieve its task.
Coming to the second point, you cannot find out the size of an object in an image unless you have any reference(known) sized object in the image. If the image was captured from a closer distance, the card will seem larger and if taken from far, the card will seem smaller. So while capturing, you will have to enforce some restrictions like you can ask the user to capture image along with some standard ruler. You can also ask the user to capture image on an A4 sheet with all the sheet edges visible. Since, you know the size of the A4 sheet, you'll be able to estimate the size of the card.
Apart from above methods, if you have enough data set of such images, you can use Haar Classifiers or Neural Network/Deep Learning based methods to do this with much better accuracy.
Related
In a project, we are creating a virtual tour of an apartment. We want to display the room dimension in that virtual image. So far we are using RICO theta v to create the virtual tour. One example is given below.
The first image shows a panoramic view of the room. Now using Lidar we want to measure the room length and width. My question is: is there any way where i could attach this Lidar information to the image that I got from the RICO. so that the user can measure the distance from the picture or we can display the length and width of the room.
so, in short, I want to know:
1. What could be the possible solution to modify the image based on Lidar output?
2. Is there any way where I could find room dimensions using Lidar output?
I will be so glad if you give me some ideas.
The LIDAR sensor outputs a pointcloud, which is a 3D representation of your room. Every point in the 3D pointcloud represents a small point in the room, and the distances between points are distances between real objects.
Therefore, you would only need to know which points correspond to the corners of the room, and then you could measure the distance between them and compute the area. There can be some options of automatically detecting corners in the pointcloud, some of which are suggested here: How to find corner points of any object in point cloud and find distance between corner points in inch/cm/m?
The problem is that this is not as easy to correlate with an image. One approach, assuming a static setup, would be to manually align the pointcloud with the image.
Also, as there are approaches for automatic corner detection in the pointcloud, there are some options for automatic corner detection in images, such as the Harris corner detector.
Of course, all these methods will be prone to detecting all corners in the image, so some heuristics for filtering them might be needed.
I want multiple users to take photographs of a paper which has four dots at the four edges. While user is taking photograph, to make sure that the paper is flat and not crumpled, I want an overlaid frame to turn green, if the camera can detect four dots with the known relative distance, thus signifying the correct position of paper for photograph.
I have zero knowledge of image processing. Let me know if it is even possible, considering the camera application of both iOS and Android.
First you have not put your question in clear way, still I will try to give you an answer, you can use language of your choice, I am assuming that in the frame there will be paper only, and background should be uniform.
1) Threshold your image for detection of Paper only.
2) Once you have a binary image with paper you can extract its contour information. (In opencv use contours = cv2.findContours(thresholdimage, cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE))
3) Get corner points of the contour. (In opencv you can usecv2.approxPolyDP and get list of the points).
From here you have multiple options, if you want to check alignment of paper is correct or not, use position of points. or you can find distance between them.
to check alignment of your rectangle you can find arctan between points which should be perpendicular in ideal case, you can use it as a measure.
Thank You.
I am trying to detect circular road signs and I have some issues.
The HoughCircles function detects circles in a gray image, however with the same parameters but the image binarized (the circle is still perfectly visible) it does not detect any circle. I do not why it fails a lot with a binarized image. Any ideas why I have this issue with binary images?
To try to correct that I set the dp parameter to 2 and changed the threshold. In the binary image I now detect circles, but it also gives me a lot of false positives. I do not understand what the dp parameter is, or how to use it.
If there is no way to make it work, I would like to know if there is any other way of detecting circles in an image.
Hough generally works well with bad data - partial or obscured circles and noise.
But it is sensitive to the tuning parameters (max, min diameter, number of votes for a result).
Typically you could run hough to find all possible circles and then examine each possible circle by eg checking distance from center to points on the circumference. Or you could look at found circle diameters and then refine your diameter/vote bins, especially if this is a video stream and you expect the circles to be similar in the future.
I am interested in detecting single object more precisely a fire extinguisher which has no inter class variability (all fire extinguisher looks same). However, The application is supposedly realtime i.e a robot is exploring the environment and whenever it sees the object of interest it should be able to detect it and give pixel coordinates of it.
My question is which algorithm will be good choice for this task?
1. Is this a classification problem and should we use features(sift/surf etc) + bow +svm?
2. some other solution (no idea yet).
Any kind of input will be appreciated.
Thanks.
(P.S bear with me i am newbie to computer vision and stack over flow)
update1:
Height varies all are mounted on the wall but with different height. I tried with SIFT features and bow but it is expensive to extract bow descriptors in testing part. Moreover I have no idea how to locate the object(pixel coordinates) inside the image after its been classified positive.
update 2:
I finally used sift + bow + svm and am able to classify the object. But using this technique, i only get output interms of whether the object is present in the scene or not?
How can i detect the object i.e getting the bounding box or centre of the object. what is the compatible approach with the above method for achieving these results.
Thank you all.
I would suggest using color as the main feature to look for, and only try other features as needed. The fire extinguisher red is very distinctive, and should not occur too often elsewhere in an office environment. Other, more computationally expensive tests can then be performed only in regions of the right color.
Here is a good tutorial for color detection that also explains how to find good thresholds for your desired color.
I would suggest the following approach:
denoise your image with a median filter
convert the image to HSV format (Hue, Saturation, Value)
select pixels close to that particular shade of red with InRange()
Now you have a binary image image that contains only the pixels that are red.
count the number of red pixels with CountNonZero()
If that number is too small, abort
remove noise from the binary image by morphological opening / closing
find contours of all blobs in your picture with findContours or the CvBlob library
check if there are blobs of the correct width, correct height and correct width/height ratio
since your fire extinguishers are vertical cylinders, the width/height ratio will be constant from every angle. The width and height will of course vary somewhat with distance to the camera.
if the width and height do not match, abort
repeat these steps to find the black-colored part on the bottom of the extinguisher,
abort if there is no black region with correct width/height below the red region
(perhaps also repeat these steps for the metallic top and the yellow rectangle)
These tests should all be very fast. If they are too slow, you could reduce the resolution of your input images.
Depending on your environment, it is possible that this is already a robust enough test. If not, you can proceed with sift/surf feature matching, but only in a small region around the blobs with the correct color. You also do not necessarily have to do that for each frame, each n-th frame should be be enough for confirmation.
This is a old question .. but will still like to give my recommendation to use YOLO algorithm to solve this problem.
YOLO fits very well to this scenario.
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.