Affichage des articles dont le libellé est emgu. Afficher tous les articles
OpenCV Tutorial 9: Shape Detection and Color Filtering in Emgu CV
OpenCV Tutorial 9: Shape Detection and Color Filtering in Emgu CV
Object detection and segmaentation is the most important and challenging fundamental task of computer vision. It is a critical part in many applications such as image search, image auto-annotation and scene understanding. However it is still an open problem due to the complexity of object classes and images.
The easiest way to detect and segment an object from an image is the color based methods . The colors in the object and the background should have a significant color difference in order to segment objects sucessfully using color based methods.
Program to add a trackbar slider to the basic viewer window: when the slider is moved, the function onTrackbarSlide() is called
Program to add a trackbar slider to the basic viewer window: when the slider is moved, the function onTrackbarSlide() is called and then passed to the slider’s new value
#include “cv.h”
#include “highgui.h”
int g_slider_position = 0;
CvCapture* g_capture = NULL;
void onTrackbarSlide(int pos) {
cvSetCaptureProperty(
g_capture,
CV_CAP_PROP_POS_FRAMES,
pos
);
}
int main( int argc, char** argv ) {
cvNamedWindow( “Example3”, CV_WINDOW_AUTOSIZE );
g_capture = cvCreateFileCapture( argv[1] );
int frames = (int) cvGetCaptureProperty(
g_capture,
CV_CAP_PROP_FRAME_COUNT
);
if( frames!= 0 ) {
cvCreateTrackbar(
“Position”,
“Example3”,
&g_slider_position,
frames,
onTrackbarSlide
);
}
IplImage* frame;
// While loop (as in Example 2) capture & show video
…
// Release memory and destroy window
…
return(0);
}
Now we defi ne a callback routine to be used when the user pokes the slider. Th is routine will be passed to a 32-bit integer, which will be the slider position. Th e call to cvSetCaptureProperty() is one we will see oft en in the future, along with its counterpart cvGetCaptureProperty(). Th ese routines allow us to confi gure (or query in the latter case) various properties of the CvCapture object. In this case we pass the argument CV_CAP_PROP_POS_FRAMES, which indicates that we would like to set the read position in units of frames. (We can use AVI_RATIO instead of FRAMES if we want to set the position as a fraction of the overall video length). Finally, we pass in the new value of the position. Because HighGUI is highly civilized, it will automatically handle such issues as the possibility that the frame we have requested is not a key-frame; it will start at the previous key-frame and fast forward up to the requested frame without us having to fuss with such details. int frames = (int) cvGetCaptureProperty( g_capture, CV_CAP_PROP_FRAME_COUNT ); As promised, we use cvGetCaptureProperty()when we want to query some data from the CvCapture structure. In this case, we want to fi nd out how many frames are in the video so that we can calibrate the slider (in the next step). if( frames!= 0 ) { cvCreateTrackbar( “Position”, “Example3”, &g_slider_position, frames, onTrackbarSlide ); } The last detail is to create the trackbar itself. Th e function cvCreateTrackbar() allows us to give the trackbar a label* (in this case Position) and to specify a window to put the trackbar in. We then provide a variable that will be bound to the trackbar, the maximum value of the trackbar, and a callback (or NULL if we don’t want one) for when the slider is moved. Observe that we do not create the trackbar if cvGetCaptureProperty() returned a zero frame count. Th is is because sometimes, depending on how the video was encoded, the total number of frames will not be available. In this case we will just play the movie without providing a trackbar. It is worth noting that the slider created by HighGUI is not as full-featured as some sliders out there. Of course, there’s no reason you can’t use your favorite windowing toolkit instead of HighGUI, but the HighGUI tools are quick to implement and get us off the ground in a hurry. Finally, we did not include the extra tidbit of code needed to make the slider move as the video plays. Th is is left as an exercise for the reader. Learn more »
simple OpenCV program for playing a video fi le from disk
simple OpenCV program for playing a video fi le from disk
Playing a video with OpenCV is almost as easy as displaying a single picture. Th e only new issue we face is that we need some kind of loop to read each frame in sequence; we may also need some way to get out of that loop if the movie is too boring. See ExampleExample 2-2. A simple OpenCV program for playing a video fi le from disk
#include “highgui.h”
int main( int argc, char** argv ) {
cvNamedWindow( “Example2”, CV_WINDOW_AUTOSIZE );
CvCapture* capture = cvCreateFileCapture( argv[1] );
IplImage* frame;
while(1) {
frame = cvQueryFrame( capture );
if( !frame ) break;
cvShowImage( “Example2”, frame );
char c = cvWaitKey(33);
if( c == 27 ) break;
}
cvReleaseCapture( &capture );
cvDestroyWindow( “Example2” );
}
Here we begin the function main() with the usual creation of a named window, in this case “Example2”. Th ings get a little more interesting aft er that. CvCapture* capture = cvCreateFileCapture( argv[1] ); Th e function cvCreateFileCapture() takes as its argument the name of the AVI fi le to be loaded and then returns a pointer to a CvCapture structure. Th is structure contains all of the information about the AVI fi le being read, including state information. When created in this way,
the CvCapture structure is initialized to the beginning of the AVI. frame = cvQueryFrame( capture ); Once inside of the while(1) loop, we begin reading from the AVI fi le. cvQueryFrame() takes as its argument a pointer to a CvCapture structure. It then grabs the next video frame into memory (memory that is actually part of the CvCapture structure). A pointer is returned to that frame. Unlike cvLoadImage, which actually allocates memory for the image, cvQueryFrame uses memory already allocated in the CvCapture structure. Th us it will not be necessary (or wise) to call cvReleaseImage() for this “frame” pointer. Instead, the frame image memory will be freed when the CvCapture structure is released. c = cvWaitKey(33); if( c == 27 ) break; Once we have displayed the frame, we then wait for 33 ms.*
If the user hits a key, then c will be set to the ASCII value of that key; if not, then it will be set to –1. If the user hits the Esc key (ASCII 27), then we will exit the read loop. Otherwise, 33 ms will pass and we will just execute the loop again. It is worth noting that, in this simple example, we are not explicitly controlling the speed of the video in any intelligent way. We are relying solely on the timer in cvWaitKey() to pace the loading of frames. In a more sophisticated application it would be wise to read the actual frame rate from the CvCapture structure (from the AVI) and behave accordingly! cvReleaseCapture( &capture ); When we have exited the read loop—because there was no more video data or because the user hit the Esc key—we can free the memory associated with the CvCapture structure. Th is will also close any open fi le handles to the AVI file.
simple OpenCV program that loads an image from disk and displays it on the screen
Introduction to OpenCV EmguCV
Display a Picture
First Program—Display a Picture
OpenCV provides utilities for reading from a wide array of image fi le types as well as from video and cameras. Th ese utilities are part of a toolkit called HighGUI, which is included in the OpenCV package. We will use some of these utilities to create a simple program that opens an image and displays it on the screen. See Example
#include “highgui.h”
int main( int argc, char** argv ) {
IplImage* img = cvLoadImage( argv[1] );
cvNamedWindow( “Example1”, CV_WINDOW_AUTOSIZE );
cvShowImage( “Example1”, img );
cvWaitKey(0);
cvReleaseImage( &img );
cvDestroyWindow( “Example1” );
}
When compiled and run from the command line with a single argument, this program loads an image into memory and displays it on the screen. It then waits until the user presses a key, at which time it closes the window and exits. Let’s go through the program line by line and take a moment to understand what each command is doing.
IplImage* img = cvLoadImage( argv[1] );
This line loads the image.* Th e function cvLoadImage() is a high-level routine that determines
the file format to be loaded based on the file name; it also automatically allocates
the memory needed for the image data structure. Note that cvLoadImage() can read a wide variety of image formats, including BMP, DIB, JPEG, JPE, PNG, PBM, PGM, PPM, SR, RAS, and TIFF. A pointer to an allocated image data structure is then returned.
This structure, called IplImage, is the OpenCV construct with which you will deal the most. OpenCV uses this structure to handle all kinds of images: single-channel, multichannel, integer-valued, floating-point-valued, et cetera. We use the pointer that
cvLoadImage() returns to manipulate the image and the image data.
cvNamedWindow( “Example1”, CV_WINDOW_AUTOSIZE );
Another high-level function, cvNamedWindow(), opens a window on the screen that can contain and display an image.
This function, provided by the HighGUI library, also assigns a name to the window (in this case, “Example1”). Future HighGUI calls that interact with this window will refer to it by this name. The second argument to cvNamedWindow() defi nes window properties. It may be set either to 0 (the default value) or to CV_WINDOW_AUTOSIZE. In the former case, the size of the window will be the same regardless of the image size, and the image will be scaled to fit within the window. In the latter case, the window will expand or contract automatically when an image is loaded so as to accommodate the image’s true size.
cvShowImage( “Example1”, img );
Whenever we have an image in the form of an IplImage* pointer, we can display it in an existing window with cvShowImage(). Th e cvShowImage() function requires that a named window already exist (created by cvNamedWindow()). On the call to cvShowImage(), the window will be redrawn with the appropriate image in it, and the window will resize itself as appropriate if it was created using the CV_WINDOW_AUTOSIZE flag cvWaitKey(0);
The cvWaitKey() function asks the program to stop and wait for a keystroke. If a positive argument is given, the program will wait for that number of milliseconds and then continue even if nothing is pressed. If the argument is set to 0 or to a negative number, the program will wait indefi nitely for a keypress. cvReleaseImage( &img );
Once we are through with an image, we can free the allocated memory. OpenCV expects a pointer to the IplImage* pointer for this operation. Aft er the call is completed, the pointer img will be set to NULL. cvDestroyWindow( “Example1” );
Finally, we can destroy the window itself. Th e function cvDestroyWindow() will close the window and de-allocate any associated memory usage (including the window’s internal image buff er, which is holding a copy of the pixel information from *img). For a simple program, you don’t really have to call cvDestroyWindow() or cvReleaseImage() because all the resources and windows of the application are closed automatically by the operating system upon exit, but it’s a good habit anyway.
Now that we have this simple program we can toy around with it in various ways, but we don’t want to get ahead of ourselves. Our next task will be to construct a very simple almost as simple as this one—program to read in and display an AVI video fi le. After that, we will start to tinker a little more.
#include “highgui.h”
int main( int argc, char** argv ) {
IplImage* img = cvLoadImage( argv[1] );
cvNamedWindow( “Example1”, CV_WINDOW_AUTOSIZE );
cvShowImage( “Example1”, img );
cvWaitKey(0);
cvReleaseImage( &img );
cvDestroyWindow( “Example1” );
}
When compiled and run from the command line with a single argument, this program loads an image into memory and displays it on the screen. It then waits until the user presses a key, at which time it closes the window and exits. Let’s go through the program line by line and take a moment to understand what each command is doing.
IplImage* img = cvLoadImage( argv[1] );
This line loads the image.* Th e function cvLoadImage() is a high-level routine that determines
the file format to be loaded based on the file name; it also automatically allocates
the memory needed for the image data structure. Note that cvLoadImage() can read a wide variety of image formats, including BMP, DIB, JPEG, JPE, PNG, PBM, PGM, PPM, SR, RAS, and TIFF. A pointer to an allocated image data structure is then returned.
This structure, called IplImage, is the OpenCV construct with which you will deal the most. OpenCV uses this structure to handle all kinds of images: single-channel, multichannel, integer-valued, floating-point-valued, et cetera. We use the pointer that
cvLoadImage() returns to manipulate the image and the image data.
cvNamedWindow( “Example1”, CV_WINDOW_AUTOSIZE );
Another high-level function, cvNamedWindow(), opens a window on the screen that can contain and display an image.
cvShowImage( “Example1”, img );
Whenever we have an image in the form of an IplImage* pointer, we can display it in an existing window with cvShowImage(). Th e cvShowImage() function requires that a named window already exist (created by cvNamedWindow()). On the call to cvShowImage(), the window will be redrawn with the appropriate image in it, and the window will resize itself as appropriate if it was created using the CV_WINDOW_AUTOSIZE flag cvWaitKey(0);
The cvWaitKey() function asks the program to stop and wait for a keystroke. If a positive argument is given, the program will wait for that number of milliseconds and then continue even if nothing is pressed. If the argument is set to 0 or to a negative number, the program will wait indefi nitely for a keypress. cvReleaseImage( &img );
Once we are through with an image, we can free the allocated memory. OpenCV expects a pointer to the IplImage* pointer for this operation. Aft er the call is completed, the pointer img will be set to NULL. cvDestroyWindow( “Example1” );
Finally, we can destroy the window itself. Th e function cvDestroyWindow() will close the window and de-allocate any associated memory usage (including the window’s internal image buff er, which is holding a copy of the pixel information from *img). For a simple program, you don’t really have to call cvDestroyWindow() or cvReleaseImage() because all the resources and windows of the application are closed automatically by the operating system upon exit, but it’s a good habit anyway.
Now that we have this simple program we can toy around with it in various ways, but we don’t want to get ahead of ourselves. Our next task will be to construct a very simple almost as simple as this one—program to read in and display an AVI video fi le. After that, we will start to tinker a little more.
OpenCV tutorial,covering configuration of Microsoft Visual Studio 2010 with OpenCV and with Emgu CV
Please bear in mind that responding to comments on my YouTube channel for specific errors is not possible in many cases. In addition to working a full time job (actually often full time and then some), I am often working on new projects, making the videos for new projects, and updating my website, all of which are very time consuming.
If I was preparing demo projects and videos for a company's products as a full time paying job I could provide troubleshooting assistance to all users, however currently I'm doing this as an unpaid hobby side-thing in addition to many other time commitments, therefore due to time constraints I am not able to provide specific troubleshooting assistance to every user.
That said, if you have followed this tutorial and encountered an obscure error at some point, I can offer the following suggestions:
1) Please watch the video a second time if you have not already and verify that all steps have been followed as stated. The computer I used to make the video is a standard off the shelf Windows 7 computer, and all configuration steps are shown and explained. If your hardware and operating system are the same or similar and an error is encountered, most likely either a seemingly minor step was accidentally skipped or not done identically to the video, or a minor typo was entered at some point.
2) If #1 does not resolve the concern, please proceed with the instructions in the 3rd OpenCV tutorial to compile OpenCV from source on your computer, then follow the configuration steps in the video again for that build of OpenCV, making sure to compile the program at the end with the same compiler as was used to compile OpenCV from source.
3) If #2 does not resolve the concern, please follow the steps in OpenCV tutorial 2, 4, or 5 to use OpenCV 2.x functions, or OpenCV in Qt, or Emgu CV in Visual Studio. It is extremely unlikely that none of these will work unless there is something severely wrong with your computer hardware or operating system install.
4) If none of the above resolved the concern, please repeat #1, #2, and #3 on a different computer.
EmguCV Tutorial : Pedestrian Detection using Histogram of Oriented Gradients
Histogram of Oriented Gradients (HOG) are feature descriptors used in computer vision and image processing for the purpose of object detection. The technique counts occurrences of gradient orientation in localized portions of an image. This method is similar to that of edge orientation histograms, scale-invariant feature transform descriptors, and shape contexts, but differs in that it is computed on a dense grid of uniformly spaced cells and uses overlapping local contrast normalization for improved accuracy.
Navneet Dalal and Bill Triggs, researchers for the French National Institute for Research in Computer Science and Control (INRIA), first described Histogram of Oriented Gradient descriptors in their June 2005 CVPR paper. In this work they focused their algorithm on the problem of pedestrian detection in static images, although since then they expanded their tests to include human detection in film and video, as well as to a variety of common animals and vehicles in static imagery.
OpenCV Tutorial 10: Optical Character Recognition (OCR) in Emgu CV
En géométrie, le tesseract, aussi appelé 8-cellules ou octachore, est l'analogue quadridimensionnel du cube (tri-dimensionnel), où le mouvement le long de la quatrième dimension est souvent une représentation pour des transformations liées du cube à travers le temps. Le tesseract est au cube ce que le cube est au carré ; ou, plus formellement, le tesseract peut être décrit comme un 4-polytope régulier convexe dont les frontières sont constituées par huit cellules cubiques.
Une généralisation du cube aux dimensions plus grandes que trois est appelée un “hypercube”, “n-cube” ou “polytope de mesure”. Le tesseract est l'hypercube quadridimensionnel ou 4-cube. C'est un polytope régulier. C'est aussi un cas particulier de parallélotope : un hypercube est un parallélotope droit dont les arêtes sont de même longueur.
Selon l'Oxford English Dictionary, le mot « tesseract » a été conçu et utilisé pour la première fois en 1888 par Charles Howard Hinton dans son livre A New Era of Thought, à partir du τεσσερες ακτινες (« quatre rayons ») ionique grec, faisant référence aux quatre droites à partir de chaque sommet vers les autres sommets. De manière alternative, d'autres personnes ont appelé la même figure un “tétracube”.
OpenCV tutorial : Face and Eye Detection with Emgu CV
In this video we perform face and eye detection using Emgu CV, Visual Basic, and the default Haar classifier xlm files.
I've got more planned for the near future, stay tuned!
I've got more planned for the near future, stay tuned!
Learn more »
OpenCV tutorial 5: Ball tracker Emgu CV with C#
OpenCV tutorial 5: Emgu CV with C#
Inscription à :
Articles (Atom)
Copyright © 2013 Videos Tutoriels and Blogger Templates








