Skip to content

Commit

Permalink
optimize maixvision trans and yolo11 draw points
Browse files Browse the repository at this point in the history
  • Loading branch information
Neutree committed Nov 15, 2024
1 parent a265ff7 commit f8b81bb
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion components/nn/include/maix_nn_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ namespace maix::nn

/**
* Get object item
* @maixpy maix.nn.Objects.__item__
* @maixpy maix.nn.Objects.__getitem__
* @maixcdk maix.nn.Objects.[]
*/
nn::Object &operator[](int idx)
Expand Down
2 changes: 1 addition & 1 deletion components/nn/include/maix_nn_ocr_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ namespace maix::nn

/**
* Get object item
* @maixpy maix.nn.OCR_Objects.__item__
* @maixpy maix.nn.OCR_Objects.__getitem__
* @maixcdk maix.nn.OCR_Objects.[]
*/
nn::OCR_Object &operator[](int idx)
Expand Down
4 changes: 2 additions & 2 deletions components/nn/include/maix_nn_yolo11.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,12 @@ namespace maix::nn
int y2 = points[pos[i * 2 + 1] * 2 + 1];
if (x1 < 0 || y1 < 0 || x2 < 0 || y2 < 0)
continue;
img.draw_line(x1, y1, x2, y2, image::COLOR_RED, 2);
img.draw_line(x1, y1, x2, y2, color, 2);
}
int x = (points[5 * 2] + points[6 * 2]) / 2;
int y = (points[5 * 2 + 1] + points[6 * 2 + 1]) / 2;
if (!(points[5 * 2] < 0 || points[5 * 2 + 1] < 0 || points[6 * 2] < 0 || points[6 * 2 + 1] < 0 || x < 0 || y < 0 || points[0] < 0 || points[1] < 0))
img.draw_line(points[0], points[1], x, y, image::COLOR_RED, 2);
img.draw_line(points[0], points[1], x, y, color, 2);
}
for (size_t i = 0; i < points.size() / 2; ++i)
{
Expand Down
7 changes: 7 additions & 0 deletions components/vision/include/maix_display.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,11 @@ namespace maix::display
* @maixpy maix.display.send_to_maixvision
*/
void send_to_maixvision(image::Image &img);

/**
* Set image transport quality(only for JPEG)
* @param quality default 95, value from 51 ~ 100
* @maixpy maix.display.set_trans_image_quality
*/
void set_trans_image_quality(const int value);
}
1 change: 1 addition & 0 deletions components/vision/include_private/maix_image_trans.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace maix
err::Err send_image(image::Image &img);
err::Err set_format(image::Format fmt, int quality = 95);
image::Format get_format() { return _fmt; }
void set_quality(const int quality) { _quality = quality; }

private:
void *_handle;
Expand Down
6 changes: 6 additions & 0 deletions components/vision/src/maix_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,10 @@ namespace maix::display

}

void set_trans_image_quality(const int value)
{
if(img_trans)
img_trans->set_quality(value);
}

} // namespace maix::display
11 changes: 10 additions & 1 deletion components/vision/src/maix_image_trans.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ using websocketpp::lib::placeholders::_2;
#define IMG_ENCODE_JPEG 1
#define IMG_ENCODE_PNG 2

static int jpeg_quality = 95;

enum ImageTransFmt
{
IMG_TRANS_FMT_NONE = 0, // pause trans
Expand Down Expand Up @@ -454,7 +456,14 @@ namespace maix
// compress image to jpeg
if (img.format() != _fmt)
{
compressed = img.to_format(_fmt);
if(_fmt == image::FMT_JPEG)
{
compressed = img.to_jpeg(this->_quality);
}
else
{
compressed = img.to_format(_fmt);
}
if (compressed == nullptr)
{
log::error("compress image failed\n");
Expand Down

0 comments on commit f8b81bb

Please sign in to comment.