Skip to content

Commit

Permalink
Merge pull request leggedrobotics#182 from leggedrobotics/fix/image_p…
Browse files Browse the repository at this point in the history
…ublisher

Fixed copy of image publisher.
  • Loading branch information
mbjelonic authored Oct 2, 2019
2 parents ac666ab + d09e2a8 commit 687d8f9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions darknet_ros/include/darknet_ros/image_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

#include "image.h"

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

#endif
2 changes: 2 additions & 0 deletions darknet_ros/src/YoloObjectDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,8 @@ void YoloObjectDetector::yolo()
demoTime_ = what_time_is_it_now();
if (viewImage_) {
displayInThread(0);
} else {
generate_image(buff_[(buffIndex_ + 1)%3], ipl_);
}
publishInThread();
} else {
Expand Down
24 changes: 24 additions & 0 deletions darknet_ros/src/image_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

#include "darknet_ros/image_interface.h"

static float get_pixel(image m, int x, int y, int c)
{
assert(x < m.w && y < m.h && c < m.c);
return m.data[c*m.h*m.w + y*m.w + x];
}

image **load_alphabet_with_file(char *datafile) {
int i, j;
const int nsize = 8;
Expand All @@ -26,3 +32,21 @@ image **load_alphabet_with_file(char *datafile) {
}
return alphabets;
}

#ifdef OPENCV
void generate_image(image p, IplImage *disp)
{
int x,y,k;
if(p.c == 3) rgbgr_image(p);
//normalize_image(copy);

int step = disp->widthStep;
for(y = 0; y < p.h; ++y){
for(x = 0; x < p.w; ++x){
for(k= 0; k < p.c; ++k){
disp->imageData[y*step + x*p.c + k] = (unsigned char)(get_pixel(p,x,y,k)*255);
}
}
}
}
#endif

0 comments on commit 687d8f9

Please sign in to comment.