Skip to content

Commit 687d8f9

Browse files
authored
Merge pull request #182 from leggedrobotics/fix/image_publisher
Fixed copy of image publisher.
2 parents ac666ab + d09e2a8 commit 687d8f9

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

darknet_ros/include/darknet_ros/image_interface.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
#include "image.h"
1313

14+
static float get_pixel(image m, int x, int y, int c);
1415
image **load_alphabet_with_file(char *datafile);
16+
void generate_image(image p, IplImage *disp);
1517

1618
#endif

darknet_ros/src/YoloObjectDetector.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,8 @@ void YoloObjectDetector::yolo()
541541
demoTime_ = what_time_is_it_now();
542542
if (viewImage_) {
543543
displayInThread(0);
544+
} else {
545+
generate_image(buff_[(buffIndex_ + 1)%3], ipl_);
544546
}
545547
publishInThread();
546548
} else {

darknet_ros/src/image_interface.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88

99
#include "darknet_ros/image_interface.h"
1010

11+
static float get_pixel(image m, int x, int y, int c)
12+
{
13+
assert(x < m.w && y < m.h && c < m.c);
14+
return m.data[c*m.h*m.w + y*m.w + x];
15+
}
16+
1117
image **load_alphabet_with_file(char *datafile) {
1218
int i, j;
1319
const int nsize = 8;
@@ -26,3 +32,21 @@ image **load_alphabet_with_file(char *datafile) {
2632
}
2733
return alphabets;
2834
}
35+
36+
#ifdef OPENCV
37+
void generate_image(image p, IplImage *disp)
38+
{
39+
int x,y,k;
40+
if(p.c == 3) rgbgr_image(p);
41+
//normalize_image(copy);
42+
43+
int step = disp->widthStep;
44+
for(y = 0; y < p.h; ++y){
45+
for(x = 0; x < p.w; ++x){
46+
for(k= 0; k < p.c; ++k){
47+
disp->imageData[y*step + x*p.c + k] = (unsigned char)(get_pixel(p,x,y,k)*255);
48+
}
49+
}
50+
}
51+
}
52+
#endif

0 commit comments

Comments
 (0)