~paparazzi-uav/paparazzi/v5.0-manual

« back to all changes in this revision

Viewing changes to sw/ext/opencv_bebop/opencv/samples/cpp/edge.cpp

  • Committer: Paparazzi buildbot
  • Date: 2016-05-18 15:00:29 UTC
  • Revision ID: felix.ruess+docbot@gmail.com-20160518150029-e8lgzi5kvb4p7un9
Manual import commit 4b8bbb730080dac23cf816b98908dacfabe2a8ec from v5.0 branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "opencv2/core/utility.hpp"
 
2
#include "opencv2/imgproc.hpp"
 
3
#include "opencv2/imgcodecs.hpp"
 
4
#include "opencv2/highgui.hpp"
 
5
 
 
6
#include <stdio.h>
 
7
 
 
8
using namespace cv;
 
9
using namespace std;
 
10
 
 
11
int edgeThresh = 1;
 
12
Mat image, gray, edge, cedge;
 
13
 
 
14
// define a trackbar callback
 
15
static void onTrackbar(int, void*)
 
16
{
 
17
    blur(gray, edge, Size(3,3));
 
18
 
 
19
    // Run the edge detector on grayscale
 
20
    Canny(edge, edge, edgeThresh, edgeThresh*3, 3);
 
21
    cedge = Scalar::all(0);
 
22
 
 
23
    image.copyTo(cedge, edge);
 
24
    imshow("Edge map", cedge);
 
25
}
 
26
 
 
27
static void help()
 
28
{
 
29
    printf("\nThis sample demonstrates Canny edge detection\n"
 
30
           "Call:\n"
 
31
           "    /.edge [image_name -- Default is ../data/fruits.jpg]\n\n");
 
32
}
 
33
 
 
34
const char* keys =
 
35
{
 
36
    "{help h||}{@image |../data/fruits.jpg|input image name}"
 
37
};
 
38
 
 
39
int main( int argc, const char** argv )
 
40
{
 
41
    CommandLineParser parser(argc, argv, keys);
 
42
    if (parser.has("help"))
 
43
    {
 
44
        help();
 
45
        return 0;
 
46
    }
 
47
    string filename = parser.get<string>(0);
 
48
 
 
49
    image = imread(filename, 1);
 
50
    if(image.empty())
 
51
    {
 
52
        printf("Cannot read image file: %s\n", filename.c_str());
 
53
        help();
 
54
        return -1;
 
55
    }
 
56
    cedge.create(image.size(), image.type());
 
57
    cvtColor(image, gray, COLOR_BGR2GRAY);
 
58
 
 
59
    // Create a window
 
60
    namedWindow("Edge map", 1);
 
61
 
 
62
    // create a toolbar
 
63
    createTrackbar("Canny threshold", "Edge map", &edgeThresh, 100, onTrackbar);
 
64
 
 
65
    // Show the image
 
66
    onTrackbar(0, 0);
 
67
 
 
68
    // Wait for a key stroke; the same function arranges events processing
 
69
    waitKey(0);
 
70
 
 
71
    return 0;
 
72
}