将矩形转换为圆

时间:2019-04-02 13:09:54

标签: c deep-learning drawing geometry yolo

我正在尝试使用圆来检测对象,我使用了基于yolo深度学习的暗网框架。 我必须更改此功能,然后尝试将此功能从@Test public void checkThreadUnSafeSingleton() throws InterruptedException { int threadsAmount = 500; Set<Singleton> singletonSet = Collections.newSetFromMap(new ConcurrentHashMap<>()); ExecutorService executorService = Executors.newFixedThreadPool(threadsAmount); for (int i = 0; i < threadsAmount; i++) { executorService.execute(() -> { Singleton singleton = Singleton.getInstance(); singletonSet.add(singleton); }); } executorService.shutdown(); executorService.awaitTermination(1, TimeUnit.MINUTES); Assert.assertEquals(2, singletonSet.size()); } 更改为draw_rectangle, 该怎么做?

draw_circle

因此,结果显示如下: enter image description here

https://i.imgur.com/b7Bl9Iv.png

我想将其更改为一个圆圈

1 个答案:

答案 0 :(得分:0)

这是Bresenham算法的一种简单实现,用于在您的image(改编自https://gist.github.com/bert/1085538)上绘制省略号:

void set_pixel(image a, int x, int y, float r, float g, float b) {
    if (x >= 0 && x < a.w && y >= 0 && y < a.h) {
        a.data[x + y * a.w + 0 * a.w * a.h] = r;
        a.data[x + y * a.w + 1 * a.w * a.h] = g;
        a.data[x + y * a.w + 2 * a.w * a.h] = b;
    }
}

void plot_ellipsis_rect(image a, int x0, int y0, int x1, int y1, float r, float g, float b) {
   int a = abs(x1 - x0), b = abs(y1 - y0), b1 = b & 1; /* values of diameter */
   long dx = 4 * (1 - a) * b * b, dy = 4 * (b1 + 1) * a * a; /* error increment */
   long err = dx + dy + b1 * a * a, e2; /* error of 1.step */

   y0 += (b + 1) / 2;
   y1 = y0 - b1;   /* starting pixel */
   a = 8 * a * a;
   b1 = 8 * b * b;
   do {
       set_pixel(a, x1, y0, r, g, b); /*   I. Quadrant */
       set_pixel(a, x0, y0, r, g, b); /*  II. Quadrant */
       set_pixel(a, x0, y1, r, g, b); /* III. Quadrant */
       set_pixel(a, x1, y1, r, g, b); /*  IV. Quadrant */
       e2 = 2 * err;
       if (e2 >= dx) {
          x0++;
          x1--;
          err += dx += b1;
       }
       if (e2 <= dy) {
          y0++;
          y1--;
          err += dy += a;
       }
   } while (x0 <= x1);
   while (y0 - y1 < b) {  /* too early stop of flat ellipses a=1 */
       set_pixel(a, x0 - 1, y0, r, g, b); /* -> finish tip of ellipse */
       set_pixel(a, x1 + 1, y0++, r, g, b); 
       set_pixel(a, x0 - 1, y1, r, g, b);
       set_pixel(a, x1 + 1, y1--, r, g, b); 
   }
}