Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added opencv example (simple sobel filter).
- Loading branch information
Showing
7 changed files
with
227 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
Submodule opencv_bebop
added at
9eb660