OpenCV

From ImageWiki

(Difference between revisions)
Jump to: navigation, search
(Eksempel 1)
(Eksempel 2)
Line 89: Line 89:
== Eksempel 2 ==
== Eksempel 2 ==
-
Tag billeder, find kanter og vis dem.
+
, hvor der findes kanter
 +
og deallokeres.
 +
Som tidligere kan koden findes i billedgruppens SVN (XXX: link).
 +
 
 +
#include "cxcore.h"
 +
#include "cv.h"
 +
#include "highgui.h"
 +
 +
int main()
 +
{
 +
    // Get an OpenCV camera handle
 +
    CvCapture *cam = cvCaptureFromCAM(-1);
 +
 +
    // Initialise the GUI
 +
    const char *window = "Eksempel 2";
 +
    cvNamedWindow(window, CV_WINDOW_AUTOSIZE);
 +
 +
    // Allocate an 640x480 gray scale image for the gray scale image and
 +
    // the edge image.
 +
    // This assumes that the camera returns 640x480 images.
 +
    const CvSize size = cvSize(640, 480);
 +
    IplImage *gray  = cvCreateImage(size, IPL_DEPTH_8U, 1);
 +
    IplImage *edges = cvCreateImage(size, IPL_DEPTH_8U, 1);
 +
 +
    // The main loop
 +
    while (cvWaitKey(4) == -1) {
 +
        IplImage *im = cvQueryFrame(cam);
 +
        cvCvtColor(im, gray, CV_BGR2GRAY); // Convert color image to gray scale
 +
        cvCanny(gray, edges, 1000, 750, 5); // Find edges
 +
        cvShowImage(window, edges);
 +
    }
 +
    cvSaveImage("edges.png", edges); // Save the last edge image
 +
 
 +
    // Clean up
 +
    cvDestroyAllWindows();
 +
    cvReleaseCapture(&cam);
 +
    cvReleaseImage(&gray);
 +
    cvReleaseImage(&edges);
 +
 +
    return 0;
 +
}
 +
.
== Tips og tricks ==
== Tips og tricks ==

Revision as of 12:23, 9 July 2006

Personal tools