Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void all_white(IplImage *img)
- {
- for(int i = 0; i < img->width; i++)
- {
- for(int j = 0; i < img->height; i++)
- {
- set_pixel(img, i, j, 255);
- }
- }
- }
- IplImage* rotate(float angle, IplImage *img)
- {
- IplImage *save = img;
- int cosd = cos(angle);
- int sind = sin(angle);
- int new_width = (int)((img->width) * cosd + (img->height) * sind);
- int new_height = (int)((img->height) * cosd + (img->width) * sind);
- IplImage *new = cvCreateImage(cvSize(new_width, new_height), img->depth, img->nChannels);
- all_white(img);
- int i = (new->width)/2; /* x position of the image center*/
- int j = (new->height)/2; /* y position of the image center */
- for(int x = 0; x < new->width; x++)
- {
- for(int y = 0; y < new->height; y++)
- {
- int coor_x = (int)((x-i)*cosd + (y-j)*sind + i);
- int coor_y = (int)((i-x)*sind + (y-j)*cosd + j);
- if(coor_x > 0 && coor_y > 0 && coor_x < new_width && coor_y < new_height)
- {
- set_pixel(new, x, y, get_pixel(save, coor_x, coor_y, 0));
- }
- }
- }
- printf("rotate done \n");
- return new;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement