Skip to content

Instantly share code, notes, and snippets.

@ochilab
Created June 26, 2013 06:44
Show Gist options
  • Save ochilab/5865263 to your computer and use it in GitHub Desktop.
Save ochilab/5865263 to your computer and use it in GitHub Desktop.
モザイク処理(C++/CLI)。モザイクサイズについてはちょっと修正の必要あり。
int blue, green , red;
int tmp1, tmp2;
int x, y;
int size = 10;//モザイクサイズ
for(int y=0;y<img_frame->height;y+=size){
for(int x=0;x<img_frame->width;x+=size){
blue = 0;
green = 0;
red = 0;
for(int i=0;i<size;i++){
if( img_frame->height < (y + i) ){
break;
}
tmp1 = i;
for(int j=0;j<size;j++){
if( img_frame->width < (x + j) ){
break;
}
blue += (unsigned char)img_frame->imageData[img_frame->widthStep * (y + i) + (x + j) * 3];
green += (unsigned char)img_frame->imageData[img_frame->widthStep * (y + i) + (x + j)* 3 + 1];
red += (unsigned char)img_frame->imageData[img_frame->widthStep * (y + i) + (x + j) * 3 + 2];
tmp2 = j;
}
}
tmp1++;
tmp2++;
for(int i=0;i<tmp1;i++){
for(int j=0;j<tmp2;j++){
img_frame->imageData[img_frame->widthStep * (y + i) + (x + j) * 3] = cvRound(blue / (tmp1 * tmp2));
img_frame->imageData[img_frame->widthStep * (y + i) + (x + j) * 3 + 1] = cvRound(green / (tmp1 * tmp2));
img_frame->imageData[img_frame->widthStep * (y + i) + (x + j) * 3 + 2] = cvRound(red / (tmp1 * tmp2));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment