在已有的图像上画方框和实心圆

static int clamp_s(int value, int m_min, int m_max)
{
    int ret = value;
    if(value < m_min)
    {
        ret = m_min;
    }else if(value > m_max)
    {
        ret = m_max;
    }
    return ret;

}

int drewDot(unsigned char  *data,int width,int height,int channel , int x0,int y0,int r)
{
int x,y,k;
int min_x = x0-r;
int min_y = y0-r;
int max_x = x0+r;
int max_y = y0+r;
if(data==NULL)
{
printf("err");
}
for( y = min_y; y< max_y; y++)
{
for(x = min_x;x < max_x; x++)
{

if((x-x0)*(x-x0)+(y-y0)*(y-y0)< r * r)
{
if(channel==3)
{
data[(width * clamp_s(y, 0, width - 1) + x) * channel + 0]=255;
data[(width * clamp_s(y, 0, width - 1) + x) * channel + 1]=0;
data[(width * clamp_s(y, 0, width - 1) + x) * channel + 2]=0;
}
if(channel==4)
{
data[(width * clamp_s(y, 0, width - 1) + x) * channel + 0]=255;
data[(width * clamp_s(y, 0, width - 1) + x) * channel + 1]=0;
data[(width * clamp_s(y, 0, width - 1) + x) * channel + 2]=0;
data[(width * clamp_s(y, 0, width - 1) + x) * channel + 3]=255;
}

}

}
}
return  0;
}

int drewDrew(unsigned char * data, int width, int height, int x0, int y0, int x1, int y1, int thin)
{
int len_x= x1-x0;
int len_y= y1-y0;
int y,x;
for(y=y0;y<y0+thin;y++)
{
for(x=x0;x<x0+len_x;x++)
{
data[(width * clamp_s(y, 0, width - 1) + x) * 3 + 0]=255;
data[(width * clamp_s(y, 0, width - 1) + x) * 3 + 1]=0;
data[(width * clamp_s(y, 0, width - 1) + x) * 3 + 2]=0;
//data[y*width+x*3]=255;
//data[y*width+x*3+1]=0;
//data[y*width+x*3+2]=0;
//data[y*width+x+3]=255;
}
}




for(y=y1;y<y1+thin;y++)
{
for(x=x0;x<x0+len_x;x++)
{


data[(width * clamp_s(y, 0, width - 1) + x) * 3 + 0]=255;
data[(width * clamp_s(y, 0, width - 1) + x) * 3 + 1]=0;
data[(width * clamp_s(y, 0, width - 1) + x) * 3 + 2]=0;

}
}




for(y=y0;y<y0+len_y+thin;y++)
{
for(x=x0;x<x0+thin;x++)
{
data[(width * clamp_s(y, 0, width - 1) + x) * 3 + 0]=255;
data[(width * clamp_s(y, 0, width - 1) + x) * 3 + 1]=0;
data[(width * clamp_s(y, 0, width - 1) + x) * 3 + 2]=0;

}
}


for(y=y1-len_y;y<y1+thin;y++)
{
for(x=x1;x<x1+thin;x++)
{
data[(width * clamp_s(y, 0, width - 1) + x) * 3 + 0]=255;
data[(width * clamp_s(y, 0, width - 1) + x) * 3 + 1]=0;
data[(width * clamp_s(y, 0, width - 1) + x) * 3 + 2]=0;


}
}
return 0;
}

int drewDot_1(unsigned char * data, int width, int height, int channel, int x, int y, int r)
{
    int i, j, k;
    int RR = 0;
    for(j = y - r; j <= y + r; j ++)
    {
        for(i = x - r; i <= x + r; i ++)
        {
            RR = (j - y) * (j - y) + (i - x) * (i - x);
            for(k = 0; k < channel; k ++)
            {
                if(RR <= r * r)
                {
                    if(0 == k)
                    {
                        data[(clamp_s(j, 0, height - 1) * width + clamp_s(i, 0, width - 1)) * channel + k] = 255;
                    }else
                    {
                        data[(clamp_s(j, 0, height - 1) * width + clamp_s(i, 0, width - 1)) * channel + k] = 0;
                    }
                }
            }


        }
    }
    return 0;


}



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值