2 |
2 |
#include <vision/TargetDescriptor.h>
|
3 |
3 |
#include <geometry_msgs/Point.h>
|
4 |
4 |
#include <tf/transform_listener.h>
|
5 |
|
// include opencv
|
|
5 |
#include <opencv/cv.hpp>
|
|
6 |
//#include <cv_bridge/cv_bridge.h>
|
6 |
7 |
|
7 |
8 |
ros::Publisher pub;
|
8 |
9 |
|
... | ... | |
10 |
11 |
int sk = 255;
|
11 |
12 |
int vk = 255;
|
12 |
13 |
|
13 |
|
bool isRight(CvImagePtr img, int p){
|
|
14 |
bool isRight(cv_bridge::CvImagePtr img, int p){
|
14 |
15 |
return (img->data[p + 1] == img->data[p]);
|
15 |
16 |
}
|
16 |
17 |
|
17 |
|
bool isLeft(CvImagePtr img, int p){
|
|
18 |
bool isLeft(cv_bridge::CvImagePtr img, int p){
|
18 |
19 |
return (img->data[p - 1] == img->data[p]);
|
19 |
20 |
}
|
20 |
21 |
|
21 |
|
bool isUp(CvImagePtr img, int p){
|
22 |
|
return (img->data[p - img->width * img->nChannels] == img->data[p]);
|
|
22 |
bool isUp(cv_bridge::CvImagePtr img, int p){
|
|
23 |
return (img->data[p - img->width() * img->channels()] == img->data[p]);
|
23 |
24 |
}
|
24 |
25 |
|
25 |
|
bool isDown(CvImagePtr img, int p){
|
|
26 |
bool isDown(cv_bridge::CvImagePtr img, int p){
|
26 |
27 |
return (img->data[p + img->width * img->nChannels] == img->data[p]);
|
27 |
28 |
}
|
28 |
29 |
|
29 |
|
bool hasAnAdjacent(CvImagePtr image, int j){
|
|
30 |
bool hasAnAdjacent(cv_bridge::CvImagePtr image, int j){
|
30 |
31 |
int nl = image->height; // number of lines
|
31 |
32 |
int nc = image->width; // number of columns CHECK TO MAKE SURE THIS IS RIGHT AND NOT WITH CHANNELS
|
32 |
33 |
int pos = j / image->nChannels;
|
... | ... | |
48 |
49 |
/* Detects the blobs in an image within above defined constraints. Transforms image into 1
|
49 |
50 |
* for pixels in the blob, 0 for not in the blob.
|
50 |
51 |
*/
|
51 |
|
void detectBlobs(CvImagePtr image, int * comX, int * comY, int * area){
|
|
52 |
void detectBlobs(cv_bridge::CvImagePtr image, int * comX, int * comY, int * area){
|
52 |
53 |
int nl = image->height; // number of lines
|
53 |
54 |
int nc = image->width * image->nChannels; // number of columns
|
54 |
55 |
int step = image->widthStep; // effective width
|
... | ... | |
108 |
109 |
|
109 |
110 |
Image * source = &orig; // pointer to the image
|
110 |
111 |
|
111 |
|
CvImagePtr origRGBImage = toCvCopy(const sensor_msgs::Image& source,
|
|
112 |
cv_bridge::CvImagePtr origRGBImage = toCvCopy(const sensor_msgs::Image& source,
|
112 |
113 |
const std::string& encoding = "rgb8"); // convert to OpenCV, CHECK FOR SYNTAX
|
113 |
114 |
|
114 |
115 |
// convert to HSV
|
115 |
116 |
|
116 |
|
CvImagePtr HSVImage;
|
|
117 |
cv_bridge::CvImagePtr HSVImage;
|
117 |
118 |
cvCvtColor (origRGBImage, HSVImage, CV_RGB2HSV);
|
118 |
119 |
|
119 |
120 |
// detect blob
|