Skip to content

Commit

Permalink
* add new test for image_method
Browse files Browse the repository at this point in the history
  • Loading branch information
lxowalle committed Aug 2, 2024
1 parent c0e5bc1 commit 9aaeb67
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 8 deletions.
13 changes: 8 additions & 5 deletions examples/image_method/main/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <sys/stat.h>
#include <fcntl.h>

#include "test_image.hpp"

using namespace maix;

typedef struct {
Expand All @@ -30,7 +32,6 @@ typedef struct {

static priv_t priv;
static int cmd_init(int argc, char* argv[]);
int test_gaussion(image::Image *img);

int _main(int argc, char* argv[])
{
Expand Down Expand Up @@ -77,11 +78,12 @@ int main(int argc, char* argv[])

static void cmd_helper(void)
{
log::info("Image method index:");
for (size_t i = 0; i < priv.method_list.size(); i ++) {
log::info("[%d] %s\r\n", i, priv.method_list[i].name);
log::info("\t[%d] %s", i, priv.method_list[i].name);
}

log::info("Input <image method> <camera width> <camera height> <camera format> <camera fps> <camera buffnum>");
log::info("Input <image method index> <camera width> <camera height> <camera format> <camera fps> <camera buffnum>");
log::info("<camera format> = 0, measn image::FMT_RGB888");
log::info("<camera format> = 12, measn image::FMT_GRAYSCALE");
log::info("Example: ./image_method 0 320 240 0 60 2 // test gaussion");
Expand All @@ -96,8 +98,9 @@ static int cmd_init(int argc, char* argv[])
priv.cam_buffnum = 2;

// Config image method
priv.method_list.push_back(image_method_t{"no method", NULL});
priv.method_list.push_back(image_method_t{"no method(default)", NULL});
priv.method_list.push_back(image_method_t{"gaussian", test_gaussion});
priv.method_list.push_back(image_method_t{"find_blobs", test_find_blobs});

// Get init param
if (argc > 1) {
Expand Down Expand Up @@ -139,6 +142,6 @@ static int cmd_init(int argc, char* argv[])
} else {
log::info("Use method: %d %s", priv.image_method_idx, priv.method_list[priv.image_method_idx].name);
}
log::info("Use width:%d hieght:%d format:%d fps:%d buffer number:%d\r\n", priv.cam_w, priv.cam_h, priv.cam_fmt, priv.cam_fps, priv.cam_buffnum);
log::info("Use width:%d hieght:%d format:%d fps:%d buffer number:%d", priv.cam_w, priv.cam_h, priv.cam_fmt, priv.cam_fps, priv.cam_buffnum);
return 0;
}
20 changes: 20 additions & 0 deletions examples/image_method/main/src/test_find_blobs.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "test_image.hpp"

int test_find_blobs(image::Image *img) {
std::vector<maix::image::Blob> blobs;
std::vector<std::vector<int>> thresholds = {{46, 66, 41, 61, 3, 23}};
bool invert = false;
int x_stride = 2;
int y_stride = 1;
int area_threshold = 500;
int pixels_threshold = 500;
std::vector<int> roi = {1, 1, img->width()- 1, img->height() - 1};
blobs = img->find_blobs(thresholds, invert, roi, x_stride, y_stride, area_threshold, pixels_threshold);
for (auto &a : blobs) {
std::vector<std::vector<int>> mini_corners = a.mini_corners();
for (int i = 0; i < 4; i ++) {
img->draw_line(mini_corners[i][0], mini_corners[i][1], mini_corners[(i + 1) % 4][0], mini_corners[(i + 1) % 4][1], maix::image::Color::from_rgb(0, 255, 0), 2);
}
}
return 0;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#include "maix_vision.hpp"

using namespace maix;
#include "test_image.hpp"

int test_gaussion(image::Image *img) {
img->gaussian(2);
Expand Down
11 changes: 11 additions & 0 deletions examples/image_method/main/src/test_image.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef __TEST_IMAGE__HPP
#define __TEST_IMAGE__HPP

#include "maix_vision.hpp"

using namespace maix;

int test_find_blobs(image::Image *img);
int test_gaussion(image::Image *img);

#endif

0 comments on commit 9aaeb67

Please sign in to comment.