您当前的位置: 首页 >  算法

qianbo_insist

暂无认证

  • 0浏览

    0关注

    399博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

图像缩放和合并算法

qianbo_insist 发布时间:2022-07-23 22:04:55 ,浏览量:0

show me the code

一个缩放一个合并,读者自己读吧


/*

  lrgb:   input 24bits rgb buffer
  srgb:   output 24bits rgb buffer
  width:  input width
  height: input height
  xscale: changed vector
  yscale: changed vector 
*/
//注意:钱波
//无论是正的还是反的都没有关系,不要在意,因为输入是一副图像,不要忘了这一点
uint8_t * scale(unsigned char *inrgb, int width, int height,
	float xscale, //摄像头画面x轴缩放
	float yscale, //摄像头画面Y轴缩放
	int &outw,
	int &outh,
	uint8_t * deskrgb, //叠加的大画布 
	int outrgbpitch   //大画布的pitch,一行占用像素,rgb24是 w*3
)
{
	int in = 0, out = 0;
	int ox, oy;     //the pixel site is after changed
	int rx, ry;     //the pixel site is before changed
	int temp = 0;   //turn site(x,y) to memory storage
	outw = width * xscale;      //after changed width
	outh = height * yscale;    //after changed height

	int pitch = outw * outh * 3;
	int memlen = pitch * outh;
	unsigned char *outrgb = new uint8_t[memlen];

										//rx = ox/xscale + 0.5;// out--to--input
										//ry = oy/yscale + 0.5;// out--to--input
	for (oy = 0; oy = height)
			ry--;
		temp = ry * width * 3;//origion pixel site of which width

		for (ox = 0; ox = width)
				rx--;
			in = temp + rx * 3;//change site(x,y) to storage

outrgb[out + 0] = inrgb[in + 0];
outrgb[out + 1] = inrgb[in + 1];
outrgb[out + 2] = inrgb[in + 2];
out += 3;
		}
		//outrgb += outrgbpitch;
	}

	return outrgb;
}
//合并rgb24,
//如果是摄像头是4:3 则取摄像头画面的16:9 
//注意,came画面是反的,desk是正的,所以,算法要倒算
void merge_rgb(uint8_t *desk, int sw, int sh, uint8_t *came,

	int cw,  //摄像头画面宽度
	int ch,  //摄像头画面高度
	float xscale, //摄像头画面x轴缩放
	float yscale) //摄像头画面y轴缩放
{

	int pitch = cw * 3;
	uint8_t * src = came + pitch *(ch - 1); //camera 的 最后一行

	//把画面移动到右上角,离顶50像素,离右边20像素
	int right_distance = cw*xscale * 3 + 20 * 3;
	uint8_t * dst = desk + (sw * 3 * 50 - right_distance);

	//裁剪16:9
	int tempdh = cw * 9 / 16;
	if (tempdh > ch)
		tempdh = ch;
	uint8_t *src1 = came + pitch *(ch - tempdh);
	int outw, outh;
	uint8_t * out = scale(src1, cw, tempdh, xscale, yscale, outw, outh, desk, sw * 3);

	src = out + outw * 3 * (outh - 1);

	//return;
	//取其中的dw ,dh 的小画面
	//开始缩放,直接内存开始读取
	//

	//把画面移动到中间位置
	//uint8_t * dst = desk + sw * 3 / 2 - dw * 3 / 2;
//omp_set_num_threads(4);
//#pragma omp parallel
	//{
//#pragma omp for
	for (int i = 0; i             
关注
打赏
1663161521
查看更多评论
0.0409s