Skip to content

Commit

Permalink
Added opencv example (#1663)
Browse files Browse the repository at this point in the history
* Added opencv example (simple sobel filter).
  • Loading branch information
rmeertens authored and flixr committed May 18, 2016
1 parent eea3552 commit ce8b47d
Show file tree
Hide file tree
Showing 7 changed files with 227 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Expand Up @@ -22,3 +22,6 @@
[submodule "sw/ext/pprzlink"]
path = sw/ext/pprzlink
url = https://github.com/paparazzi/pprzlink.git
[submodule "sw/ext/opencv_bebop"]
path = sw/ext/opencv_bebop
url = https://github.com/tudelft/opencv_bebop.git
37 changes: 37 additions & 0 deletions conf/modules/cv_opencvdemo.xml
@@ -0,0 +1,37 @@
<!DOCTYPE module SYSTEM "module.dtd">

<module name="cv_opencvdemo" dir="computer_vision">
<doc>
<description>This example shows how opencv can be used on (for example) the Bebop drone.
Important to know is that sw/ext/opencv_bebop must be downloaded, and made.
After this is done the folder sw/ext/opencv_bebop/install has a opencv.xml file.
The LDFLAGS in this file should be the same as in this conf file.
</description>
</doc>
<header>
<file name="cv_opencvdemo.h"/>
</header>
<init fun="opencvdemo_init()"/>
<makefile>
<file name="cv_opencvdemo.c"/>
<file name="opencv_example.cpp"/>

<flag name="CXXFLAGS" value="I$(PAPARAZZI_SRC)/sw/ext/opencv_bebop/install/include"/>

<flag name="LDFLAGS" value="L$(PAPARAZZI_SRC)/sw/ext/opencv_bebop/install/lib" />
<flag name="LDFLAGS" value="lopencv_imgcodecs" />
<flag name="LDFLAGS" value="lopencv_imgproc" />
<flag name="LDFLAGS" value="lopencv_core" />
<flag name="LDFLAGS" value="L$(PAPARAZZI_HOME)/sw/ext/opencv_bebop/install/share/OpenCV/3rdparty/lib" />
<flag name="LDFLAGS" value="lzlib" />
<flag name="LDFLAGS" value="llibpng" />
<flag name="LDFLAGS" value="lstdc++" />
<flag name="LDFLAGS" value="ldl" />
<flag name="LDFLAGS" value="lm" />
<flag name="LDFLAGS" value="lpthread" />
<flag name="LDFLAGS" value="lrt" />

</makefile>
</module>


51 changes: 51 additions & 0 deletions sw/airborne/modules/computer_vision/cv_opencvdemo.c
@@ -0,0 +1,51 @@
/*
* Copyright (C) C. De Wagter
*
* This file is part of paparazzi
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*/
/**
* @file "modules/computer_vision/cv_opencvdemo.c"
* @author C. De Wagter
* opencv
*/

#include "modules/computer_vision/cv.h"
#include "modules/computer_vision/cv_opencvdemo.h"
#include "modules/computer_vision/opencv_example.h"


// Function
int opencv_func(struct image_t* img);
int opencv_func(struct image_t* img)
{

if (img->type == IMAGE_YUV422)
{
// Call OpenCV (C++ from paparazzi C function)
opencv_example((char*) img->buf, img->w, img->h);
}

// opencv_example(NULL, 10,10);

return FALSE;
}

void opencvdemo_init(void)
{
cv_add(opencv_func);
}

33 changes: 33 additions & 0 deletions sw/airborne/modules/computer_vision/cv_opencvdemo.h
@@ -0,0 +1,33 @@
/*
* Copyright (C) C. De Wagter
*
* This file is part of paparazzi
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*/
/**
* @file "modules/computer_vision/cv_opencvdemo.h"
* @author C. De Wagter
* opencv
*/

#ifndef CV_OPENCVDEMO_H
#define CV_OPENCVDEMO_H

extern void opencvdemo_init(void);

#endif


62 changes: 62 additions & 0 deletions sw/airborne/modules/computer_vision/opencv_example.cpp
@@ -0,0 +1,62 @@
/*
* Copyright (C) C. De Wagter
*
* This file is part of paparazzi
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*/
/**
* @file "modules/computer_vision/opencv_example.cpp"
* @author C. De Wagter
* opencv
*/


#include "opencv_example.h"



using namespace std;
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace cv;


int opencv_example(char *img, int width, int height)
{
// Create a new image, using the original bebop image.
Mat M(width, height, CV_8UC2, img);
Mat image;
// If you want a color image, uncomment this line
// cvtColor(M, image, CV_YUV2RGB_Y422);
// For a grayscale image, use this one
cvtColor(M, image, CV_YUV2GRAY_Y422);

// Blur it, because we can
blur(image, image, Size(5, 5));

// Canny edges, only works with grayscale image
int edgeThresh = 35;
Canny(image, image, edgeThresh, edgeThresh * 3);

// Convert back to YUV422, and put it in place of the original image
for (int row = 0; row < height; row++) {
for (int col = 0; col < width; col++) {
img[(row * width + col) * 2 + 1] = image.at<uint8_t>(row, col);
img[(row * width + col) * 2] = 127;
}
}
return 0;
}
40 changes: 40 additions & 0 deletions sw/airborne/modules/computer_vision/opencv_example.h
@@ -0,0 +1,40 @@
/*
* Copyright (C) C. De Wagter
*
* This file is part of paparazzi
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*/
/**
* @file "modules/computer_vision/cv_opencvdemo.h"
* @author C. De Wagter
* opencv
*/

#ifndef OPENCV_EXAMPLE_H
#define OPENCV_EXAMPLE_H

#ifdef __cplusplus
extern "C" {
#endif

int opencv_example(char *img, int width, int height);

#ifdef __cplusplus
}
#endif

#endif

1 change: 1 addition & 0 deletions sw/ext/opencv_bebop
Submodule opencv_bebop added at 9eb660

0 comments on commit ce8b47d

Please sign in to comment.