well iam trying to make an object tracker i produced the filtered image which is tracking the object and convert it to white i used this to get the filtered image
CvInvoke.cvInRangeS(HSVimg, low, high, THImg);
now iam trying to get the contours and get the center point so i used this (can't test it yet)
using (Image<Gray, Byte> canny = smoothedRedMask.Canny(100.0, 50.0))
using (MemStorage stor = new MemStorage())
{
Contour<Point> contours = canny.FindContours(
Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE,
Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_TREE,
stor);
}
so i have two questions what does canny method do ?
how do i draw a shape around the tracked object then get the center point using moment or any other method ?
u don't have to write code just give me reference to simple code that i can use
The Canny function is the implementation of an edge detection algorithm ,it uses a multi-stage algorithm to detect a wide range of edges in images.
refer to this wikipedia article or this tutorial/code to understand better.
The other part of the question is a bit more tricky as drawing a shape around the tracked object will depend on the quality of the image received after applying the canny edge detection and also the geometry of the object.
So you might want to adjust values of the canny function to suit your needs.
but you can refer to these youtube video tutorials to better understand/code your object tracking logic.
Video 1
Video 2.
Hoping it helps.
Related
I have this image :
What I try to do is detecting the contours of it. So with looking to the documentation and some code on the web I made this :
Image<Gray, byte> image = receivedImage.Convert<Gray, byte>().ThresholdBinary(new Gray(80), new Gray(255));
Emgu.CV.Util.VectorOfVectorOfPoint contours = new Emgu.CV.Util.VectorOfVectorOfPoint();
Mat hier = new Mat();
CvInvoke.FindContours(image, contours, hier, Emgu.CV.CvEnum.RetrType.External, Emgu.CV.CvEnum.ChainApproxMethod.ChainApproxSimple);
CvInvoke.DrawContours(receivedImage, contours, 0, new MCvScalar(255, 0, 0), 2);
Then it detects this contour in blue :
Now I would like to detect both rectangles in differents contours. So the result would be this :
(made with paint) So now I would like to detect the two rectangles separetely, (the blue and red rectangles would be two different contours). But I have no idea about how to do that !
Thanks in advance for your help ! ;)
The problem comes from the process of ThresholdBinary. As I assume you understand, this method will return a binary image, whereby all pixels above or equal to the threshold parameter, will be pulled up to maxValue parameter, and all those below, pulled down to 0. The produced image will consist therefore of only two values (binary), 0 or maxValue. If we follow your example with some assumed gray values:
After Image<Gray, byte> image = receivedImage.Convert<Gray, byte>().ThresholdBinary(new Gray(80), new Gray(255));, you will produce:
This is in fact the image that you are passing to CvInvoke.FindContours() and subsequently finding only the out most contour.
What you need, if indeed you want to continue with FindContours, is an algorithm that will "bin", or "bandpass" your image to first produce the following segments, each to be converted to binary, and contour detected independently.
I feel that you currently example is probably and over simplification of the problem to offer you a solution on how you might achieve that here. However please do ask another question with more realistic data, and I will be happy to provide some suggestions.
Alternatively look towards more sophisticated edge detection methods such and Canny or Sobel. This video may be a good starting point: Edge Detection
Hello I want to extract text-blocks from images and pass it to ocr for better accuracy. I have been searching on internet but not able to find suitable example for this. I am very new to this concept can anyone please help me out on the same?
This is what I want to achieve.
Note I am using EMGUCV for opencv and ocr.
I want to scan receipt mostly.
If you can help with that it would be great.
Is your text always in the same location? If yes, you will have the location of the region of interest.
//Create the rectangle
cv::Rect roi(0, 0, 500, 500);
//Create the cv::Mat with the ROI you need
cv::Mat imageRoi = image(roi)
Then you can send to the ocr this images
You can threshold your image into a binary image. After that you can use the morphologic operation "DILATE" (repeatedly) do join the letters. When the letters are joined us the "findContours()" function to extract the contour and the bounding boy of it.
I am working on c# project ,i am using aforge for line detection of particular color in a bmp image by using hough transform.When i am processing the image i get pixel format not supported exception .my images are 24bpprgb and the docs clearly tells the format supported.trying to convert it to the supported formats always ends up in the above exception.Can anyone enlighten me on this...
or can anyone tell me the necessary steps to convert the bmp 's to any of the supported formats using hough transform for line detection
In your case the image must be grayscale (8-bpp).
You can convert it using AForge Grayscale filter and then apply the Hough transform.
You can also take a look at:
https://github.com/dajuric/accord-net-extensions
The library implements generic image (Image) and it is easily convertible to AForge image.
Also it wrapps algorithms (primary for Accord.NET tough - for now).
The application I am working on currently requires functionality for Perspective Image Distortion. Basically what I want to do is to allow users to load an image into the application and adjust its perspective view properties based on 4 corner points that they can specify.
I had a look at ImageMagic. It has some distort functions with perpective adjustment but is very slow and some certain inputs are giving incorrect outputs.
Any of you guys used any other library or algorithm. I am coding in C#.
Any pointers would be much appreciated.
Thanks
This seems to be exactly what you (and I) were looking for:
http://www.codeproject.com/KB/graphics/YLScsFreeTransform.aspx
It will take an image and distort it using 4 X/Y coordinates you provide.
Fast, free, simple code. Tested and it works beautifully. Simply download the code from the link, then use FreeTransform.cs like this:
using (System.Drawing.Bitmap sourceImg = new System.Drawing.Bitmap(#"c:\image.jpg"))
{
YLScsDrawing.Imaging.Filters.FreeTransform filter = new YLScsDrawing.Imaging.Filters.FreeTransform();
filter.Bitmap = sourceImg;
// assign FourCorners (the four X/Y coords) of the new perspective shape
filter.FourCorners = new System.Drawing.PointF[] { new System.Drawing.PointF(0, 0), new System.Drawing.PointF(300, 50), new System.Drawing.PointF(300, 411), new System.Drawing.PointF(0, 461)};
filter.IsBilinearInterpolation = true; // optional for higher quality
using (System.Drawing.Bitmap perspectiveImg = filter.Bitmap)
{
// perspectiveImg contains your completed image. save the image or do whatever.
}
}
Paint .NET can do this and there are also custom implementations of the effect. You could ask for the source code or use Reflector to read it and get an idea of how to code it.
If it is a perspective transform, you should be able to specify a 4x4 transformation matrix that matches the four corners.
Calculate that matrix, then apply each pixel on the resulting image on the matrix, resulting in the "mapped" pixel. Notice that this "mapped" pixel is very likely going to lie between two or even four pixels. In this case, use your favorite interpolation algorithm (e.g. bilinear, bicubic) to get the interpolated color.
This really is the only way for it to be done and cannot be done faster. If this feature is crucial and you absolutely need it to be fast, then you'll need to offload the task to a GPU. For example, you can call upon the DirectX library to apply a perspective transformation on a texture. That can make it extremely fast, even when there is no GPU because the DirectX library uses SIMD instructions to accelerate matrix calculations and color interpolations.
Had the same problem. Here is the demo code with sources ported from gimp.
YLScsFreeTransform doesn't work as expected. Way better solution is ImageMagic
Here is how you use it in c#:
using(MagickImage image = new MagickImage("test.jpg"))
{
image.Distort(DistortMethod.Perspective, new double[] { x0,y0, newX0,newY0, x1,y1,newX1,newY1, x2,y2,newX2,newY2, x3,y3,newX3,newY3 });
control.Image = image.ToBitmap();
}
My requirement is something like this:
Lets take there is a Bitmap with a big letter 'A'.
The Bitmap is two colors (Either Black or White).
I need to skeletonize the big 'A'. (see: http://en.wikipedia.org/wiki/Topological_skeleton)
Using "Medial Axis Transforming" algorithm.
I tried my best in googling but i ended up being lost in finding a C#, C++ or at least pseudo code implementation of this algorithm.
I would like if someone could help me on this.
This page http://www.cs.sunysb.edu/~algorith/files/thinning.shtml has some sources you may wish to review.
The following two articles are the ones where the Medial Axis Transform was first proposed, so I think that you can find the algorithm to implement there. Do not expect a C++/C# implementation though.
A transformation for extracting new descriptors of shape
Shape description using weighted symmetric axis features
For the first one I was able to find a URL to a pdf. For the second one you will have to have access to ScienceDirect to download.
Another approach that you can use to extract the skeleton of a shape is by the Image Foresting Transform (IFT). It consists in representing the binary image as a graph. I made an implementation of the skeletonization by IFT in Matlab using the following article:
Multiscale skeletons by image foresting transform and its applications to neuromorphometry