Advertisement
Guest User

Untitled

a guest
Dec 5th, 2014
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.04 KB | None | 0 0
  1. void all_white(IplImage *img)
  2. {
  3.     for(int i = 0; i < img->width; i++)
  4.     {
  5.         for(int j = 0; i < img->height; i++)
  6.         {
  7.             set_pixel(img, i, j, 255);
  8.         }
  9.     }
  10. }
  11.  
  12. IplImage* rotate(float angle, IplImage *img)
  13. {
  14.     IplImage *save = img;
  15.     int cosd = cos(angle);
  16.     int sind = sin(angle);
  17.     int new_width = (int)((img->width) * cosd + (img->height) * sind);
  18.     int new_height = (int)((img->height) * cosd + (img->width) * sind);
  19.     IplImage *new = cvCreateImage(cvSize(new_width, new_height), img->depth, img->nChannels);
  20.     all_white(img);
  21.     int i = (new->width)/2; /* x position of the image center*/
  22.     int j = (new->height)/2; /* y position of the image center */
  23.     for(int x = 0; x < new->width; x++)
  24.     {
  25.         for(int y = 0; y < new->height; y++)
  26.         {
  27.             int coor_x = (int)((x-i)*cosd + (y-j)*sind + i);
  28.             int coor_y = (int)((i-x)*sind + (y-j)*cosd + j);
  29.             if(coor_x > 0 && coor_y > 0 && coor_x < new_width && coor_y < new_height)
  30.             {
  31.                 set_pixel(new, x, y, get_pixel(save, coor_x, coor_y, 0));
  32.             }
  33.         }
  34.     }
  35.     printf("rotate done \n");
  36.     return new;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement