#include "cv.h"
#include "highgui.h"
#include <stdio.h>
IplImage* front_image;
IplImage* rear_image;
IplImage* left_image;
IplImage* right_image;
IplImage* stitching_imgae;
IplImage* whole_image;
//重叠区标定点
CvPoint left_up11, left_up12;
CvPoint left_lower11, left_lower12;
CvPoint front_left11, front_left12;
CvPoint front_right11, front_right12;
CvPoint right_up11, right_up12;
CvPoint right_lower11, right_lower12;
CvPoint rear_left11, rear_left12;
CvPoint rear_right11, rear_right12;
//接缝与图像边缘交点
CvPoint left_up21, left_up22;
CvPoint left_lower21, left_lower22;
CvPoint front_left21, front_left22;
CvPoint front_right21, front_right22;
CvPoint right_up21, right_up22;
CvPoint right_lower21, right_lower22;
CvPoint rear_left21, rear_left22;
CvPoint rear_right21, rear_right22;
//
float k1, k2, k3, k4; //接鏠斜率
/**/
void stitching();
void calculate_cut_point();
void cut_image();
IplImage* rotate_image(IplImage* src, int angle);
void printf_point();
int main()
{
/*
front_image = cvLoadImage("5.png");
rear_image = rotate_image(front_image, 180);
right_image = rotate_image(front_image, 270);
left_image = rotate_image(front_image, 90);
int w = 200;
int h = 190;
*/
left_image = cvLoadImage("1.png");
rear_image = rotate_image(left_image, 90);
right_image = rotate_image(left_image, 180);
front_image = rotate_image(left_image, 270);
int w = 170;
int h = 170;
left_up11 = cvPoint(left_image->width - w, 0);
left_up12 = cvPoint(left_image->width, h);
left_lower11 = cvPoint(left_image->width - w, left_image->height);
left_lower12 = cvPoint(left_image->width, left_image->height - h);
front_left11 = cvPoint(0, front_image->height - h);
front_left12 = cvPoint(w, front_image->height);
front_right11 = cvPoint(front_image->width, front_image->height - h);
front_right12 = cvPoint(front_image->width - w, front_image->height);
right_up11 = cvPoint(w, 0);
right_up12 = cvPoint(0, h);
right_lower11 = cvPoint(w, right_image->height);
right_lower12 = cvPoint(0, right_image->height -h);
rear_left11 = cvPoint(0, h);
rear_left12 = cvPoint(w, 0);
rear_right11 = cvPoint(rear_image->width, h);
rear_right12 = cvPoint(rear_image->width - w, 0);
calculate_cut_point();
cut_image();
stitching();
whole_image = cvCreateImage(cvSize(front_image->width, left_image->height + front_left21.y + (rear_image->height - rear_left21.y)),
front_image->depth, front_image->nChannels);
cvZero(whole_image);
cvSetImageROI(stitching_imgae, cvRect(left_up21.x, 0,front_image->width,
left_image->height + front_left21.y + (rear_image->height - rear_left21.y)));
cvAdd(stitching_imgae, whole_image, whole_image);
cvResetImageROI(stitching_imgae);
printf_point();
cvNamedWindow("left_image", 1);
cvNamedWindow("right_image", 1);
cvNamedWindow("front_image", 1);
cvNamedWindow("rear_image", 1);
cvNamedWindow("stitching_image", 1);
cvNamedWindow("whole_image", 1);
cvShowImage("left_image", left_image);
cvShowImage("right_image", right_image);
cvShowImage("front_image", front_image);
cvShowImage("rear_image", rear_image);
cvShowImage("stitching_image", stitching_imgae);
cvShowImage("whole_image", whole_image);
cvSaveImage("whole_image.png", whole_image);
cvReleaseImage(&left_image);
cvReleaseImage(&right_image);
cvReleaseImage(&front_image);
cvReleaseImage(&rear_image);
cvReleaseImage(&stitching_imgae);
int c = cvWaitKey(0);
if (c == 27)
{
return -1;
}
return 0;
}
/**/
//拼接子函数
void stitching()
{
int width, height;
width = front_image->width + left_image->width + right_image->width;
height = front_image->height + rear_image->height +left_image->height;
stitching_imgae = cvCreateImage(cvSize(width, height), front_image->depth, front_image->nChannels);
cvSetImageROI(stitching_imgae, cvRect(left_up21.x, 0, front_image->width, front_image->height));
cvAdd(front_image, stitching_imgae, stitching_imgae);
cvResetImageROI(stitching_imgae);
cvSetImageROI(stitching_imgae, cvRect(0, front_left21.y, left_image->width, left_image->height));
cvAdd(left_image, stitching_imgae, stitching_imgae);
cvResetImageROI(stitching_imgae);
cvSetImageROI(stitching_imgae, cvRect(left_up21.x + front_image->width - (right_up21.x - right_up22.x), front_right21.y,
right_image->width, right_image->height));
cvAdd(right_image, stitching_imgae, stitching_imgae);
cvResetImageROI(stitching_imgae);
cvSetImageROI(stitching_imgae, cvRect(left_lower21.x, front_left21.y + left_image->height - (rear_left21.y - rear_left22.y),
rear_image->width, rear_image->height));
cvAdd(rear_image, stitching_imgae, stitching_imgae);
cvResetImageROI(stitching_imgae);
}
//剪切子函数
void cut_image()
{
int xx, yy;
//cut the left image
for (xx = 0; xx < left_image->width; ++xx) //cut the right_up corner
{
for (yy = 0; yy < left_image->height; ++yy)
{
if (yy < k1 *(xx - left_up21.x) +left_up21.y)
{
cvSet2D(left_image, yy, xx, cvScalar(0, 0, 0));
}
}
}
for (xx = 0; xx < left_image->width; ++xx) //cut the right_lower corner
{
for (yy = 0; yy < left_image->height; ++yy)
{
if (yy > k4 *(xx - left_lower21.x) +left_lower21.y)
{
cvSet2D(left_image, yy, xx, cvScalar(0, 0, 0));
}
}
}
//cut the right image
for (xx = 0; xx < right_image->width; ++xx)
{
for (yy = 0; yy < right_image->height; ++yy)
{
if (yy < k2 *(xx - right_up21.x) + right_up21.y)
{
cvSet2D(right_image, yy, xx, cvScalar(0, 0, 0));
}
}
}
for (xx = 0; xx < right_image->width; ++xx)
{
for (yy = 0; yy < right_image->height; ++yy)
{
if (yy > k3 *(xx - right_lower21.x) + right_lower21.y)
{
cvSet2D(right_image, yy, xx, cvScalar(0, 0, 0));
}
}
}
//cut the front image
for (xx = 0; xx < front_image->width; ++xx)
{
for (yy = 0; yy < front_image->height; ++yy)
{
if (yy > k1 *(xx - front_left21.x) + front_left21.y)
{
cvSet2D(front_image, yy, xx, cvScalar(0, 0, 0));
}
}
}
for (xx = 0; xx < front_image->width; ++xx)
{
for (yy = 0; yy < front_image->height; ++yy)
{
if (yy > k2 *(xx - front_right21.x) + front_right21.y)
{
cvSet2D(front_image, yy, xx, cvScalar(0, 0, 0));
}
}
}
//cut the rear image
for (xx = 0; xx < rear_image->width; ++xx)
{
for (yy = 0; yy < rear_image->height; ++yy)
{
if (yy < k4 *(xx - rear_left21.x) + rear_left21.y)
{
cvSet2D(rear_image, yy, xx, cvScalar(0, 0, 0));
}
}
}
for (xx = 0; xx < rear_image->width; ++xx)
{
for (yy = 0; yy < rear_image->height; ++yy)
{
if (yy < k3*(xx - rear_right21.x) + rear_right21.y)
{
cvSet2D(rear_image, yy, xx, cvScalar(0, 0, 0));
}
}
}
}
//计算剪切点
void calculate_cut_point()
{
k1 = ((float)left_up11.y - (float)left_up12.y)/((float)left_up11.x - (float)left_up12.x);
k2 = ((float)right_up11.y - (float)right_up12.y)/((float)right_up11.x - (float)right_up12.x);
k3 = ((float)right_lower11.y - (float)right_lower12.y)/((float)right_lower11.x - (float)right_lower12.x);
k4 = ((float)left_lower11.y - (float)left_lower12.y)/((float)left_lower11.x - (float)left_lower12.x);
left_up21.x = left_up11.x + (0 - left_up11.y)/k1;
left_up21.y = 0;
left_up22.x = left_image->width;
left_up22.y = left_up11.y + k1 * (left_image->width - left_up11.x);
left_lower21.x = left_lower11.x + (left_image->height - left_lower11.y)/k4;
left_lower21.y = left_image->height;
left_lower22.x = left_image->width;
left_lower22.y = left_lower11.y + k4 * (left_image->width - left_lower11.x);
right_up21.x = right_up11.x + (0 - right_up11.y)/k2;
right_up21.y = 0;
right_up22.x = 0;
right_up22.y = right_up11.y + k2 * (0 - right_up11.x);
right_lower21.x = right_lower11.x + (right_image->height - right_lower11.y)/k3;
right_lower21.y = right_image->height;
right_lower22.x = 0;
right_lower22.y = right_lower11.y + k3 * (0 - right_lower11.x);
front_left21.x = 0;
front_left21.y = front_left11.y + k1 * (0 - front_left11.x);
front_left22.x = front_left11.x + (front_image->height - front_left11.y)/k1;
front_left22.y = front_image->height;
front_right21.x = front_image->width;
front_right21.y = front_right11.y + k2 * (front_image->width - front_right11.x);
front_right22.x = front_right11.x + (front_image->height - front_right11.y)/k2;
front_right22.y = front_image->height;
rear_left21.x = 0;
rear_left21.y = rear_left11.y + k4 * (0 - rear_left11.x);
rear_left22.x = rear_left11.x + (0 - rear_left11.y)/k4;
rear_left22.y = 0;
rear_right21.x = rear_image->width;
rear_right21.y = rear_right11.y + k3 * (rear_image->width - rear_right11.x);
rear_right22.x = rear_right11.x + (0 - rear_right11.y)/k3;
rear_right22.y = 0;
}
//图像旋转
IplImage* rotate_image(IplImage* src, int angle)
{
IplImage* dst;
if (angle%180 == 0)
{
dst = cvCloneImage(src);
}
else
{
dst = cvCreateImage(cvSize(src->height, src->width), src->depth, src->nChannels);
}
float m[6];
CvMat M = cvMat( 2, 3, CV_32F, m );
int w = src->width;
int h = src->height;
m[0] = (float)(cos(-angle*CV_PI/180.));
m[1] = (float)(sin(-angle*CV_PI/180.));
m[2] = w*0.5f;
m[3] = -m[1];
m[4] = m[0];
m[5] = h*0.5f;
cvGetQuadrangleSubPix( src, dst, &M);
return dst;
}
//
void printf_point()
{
printf("%f , %f, %f, %f\n\n", k1, k2, k3, k4);
printf("(%d, %d) (%d, %d)\n", left_up11.x, left_up11.y, left_up12.x, left_up12.y);
printf("(%d, %d) (%d, %d)\n", left_lower11.x, left_lower11.y, left_lower12.x, left_lower12.y);
printf("(%d, %d) (%d, %d)\n", front_left11.x, front_left11.y, front_left12.x, front_left12.y);
printf("(%d, %d) (%d, %d)\n", front_right11.x, front_right11.y, front_right12.x, front_right12.y);
printf("(%d, %d) (%d, %d)\n", right_up11.x, right_up11.y, right_up12.x, right_up12.y);
printf("(%d, %d) (%d, %d)\n", right_lower11.x,right_lower11.y, right_lower12.x, right_lower12.y);
printf("(%d, %d) (%d, %d)\n", rear_left11.x, rear_left11.y, rear_left12.x, rear_left12.y);
printf("(%d, %d) (%d, %d)\n\n", rear_right11.x, rear_right11.y, rear_right12.x, rear_right12.y);
printf("(%d, %d) (%d, %d)\n", left_up21.x, left_up21.y, left_up22.x, left_up22.y);
printf("(%d, %d) (%d, %d)\n", left_lower21.x, left_lower21.y, left_lower22.x, left_lower22.y);
printf("(%d, %d) (%d, %d)\n", front_left21.x, front_left21.y, front_left22.x, front_left22.y);
printf("(%d, %d) (%d, %d)\n", front_right21.x, front_right21.y, front_right22.x, front_right22.y);
printf("(%d, %d) (%d, %d)\n", right_up21.x, right_up21.y, right_up22.x, right_up22.y);
printf("(%d, %d) (%d, %d)\n", right_lower21.x,right_lower21.y, right_lower22.x, right_lower22.y);
printf("(%d, %d) (%d, %d)\n", rear_left21.x, rear_left21.y, rear_left22.x, rear_left22.y);
printf("(%d, %d) (%d, %d)\n", rear_right21.x, rear_right21.y, rear_right22.x, rear_right22.y);
}
#include "highgui.h"
#include <stdio.h>
IplImage* front_image;
IplImage* rear_image;
IplImage* left_image;
IplImage* right_image;
IplImage* stitching_imgae;
IplImage* whole_image;
//重叠区标定点
CvPoint left_up11, left_up12;
CvPoint left_lower11, left_lower12;
CvPoint front_left11, front_left12;
CvPoint front_right11, front_right12;
CvPoint right_up11, right_up12;
CvPoint right_lower11, right_lower12;
CvPoint rear_left11, rear_left12;
CvPoint rear_right11, rear_right12;
//接缝与图像边缘交点
CvPoint left_up21, left_up22;
CvPoint left_lower21, left_lower22;
CvPoint front_left21, front_left22;
CvPoint front_right21, front_right22;
CvPoint right_up21, right_up22;
CvPoint right_lower21, right_lower22;
CvPoint rear_left21, rear_left22;
CvPoint rear_right21, rear_right22;
//
float k1, k2, k3, k4; //接鏠斜率
/**/
void stitching();
void calculate_cut_point();
void cut_image();
IplImage* rotate_image(IplImage* src, int angle);
void printf_point();
int main()
{
/*
front_image = cvLoadImage("5.png");
rear_image = rotate_image(front_image, 180);
right_image = rotate_image(front_image, 270);
left_image = rotate_image(front_image, 90);
int w = 200;
int h = 190;
*/
left_image = cvLoadImage("1.png");
rear_image = rotate_image(left_image, 90);
right_image = rotate_image(left_image, 180);
front_image = rotate_image(left_image, 270);
int w = 170;
int h = 170;
left_up11 = cvPoint(left_image->width - w, 0);
left_up12 = cvPoint(left_image->width, h);
left_lower11 = cvPoint(left_image->width - w, left_image->height);
left_lower12 = cvPoint(left_image->width, left_image->height - h);
front_left11 = cvPoint(0, front_image->height - h);
front_left12 = cvPoint(w, front_image->height);
front_right11 = cvPoint(front_image->width, front_image->height - h);
front_right12 = cvPoint(front_image->width - w, front_image->height);
right_up11 = cvPoint(w, 0);
right_up12 = cvPoint(0, h);
right_lower11 = cvPoint(w, right_image->height);
right_lower12 = cvPoint(0, right_image->height -h);
rear_left11 = cvPoint(0, h);
rear_left12 = cvPoint(w, 0);
rear_right11 = cvPoint(rear_image->width, h);
rear_right12 = cvPoint(rear_image->width - w, 0);
calculate_cut_point();
cut_image();
stitching();
whole_image = cvCreateImage(cvSize(front_image->width, left_image->height + front_left21.y + (rear_image->height - rear_left21.y)),
front_image->depth, front_image->nChannels);
cvZero(whole_image);
cvSetImageROI(stitching_imgae, cvRect(left_up21.x, 0,front_image->width,
left_image->height + front_left21.y + (rear_image->height - rear_left21.y)));
cvAdd(stitching_imgae, whole_image, whole_image);
cvResetImageROI(stitching_imgae);
printf_point();
cvNamedWindow("left_image", 1);
cvNamedWindow("right_image", 1);
cvNamedWindow("front_image", 1);
cvNamedWindow("rear_image", 1);
cvNamedWindow("stitching_image", 1);
cvNamedWindow("whole_image", 1);
cvShowImage("left_image", left_image);
cvShowImage("right_image", right_image);
cvShowImage("front_image", front_image);
cvShowImage("rear_image", rear_image);
cvShowImage("stitching_image", stitching_imgae);
cvShowImage("whole_image", whole_image);
cvSaveImage("whole_image.png", whole_image);
cvReleaseImage(&left_image);
cvReleaseImage(&right_image);
cvReleaseImage(&front_image);
cvReleaseImage(&rear_image);
cvReleaseImage(&stitching_imgae);
int c = cvWaitKey(0);
if (c == 27)
{
return -1;
}
return 0;
}
/**/
//拼接子函数
void stitching()
{
int width, height;
width = front_image->width + left_image->width + right_image->width;
height = front_image->height + rear_image->height +left_image->height;
stitching_imgae = cvCreateImage(cvSize(width, height), front_image->depth, front_image->nChannels);
cvSetImageROI(stitching_imgae, cvRect(left_up21.x, 0, front_image->width, front_image->height));
cvAdd(front_image, stitching_imgae, stitching_imgae);
cvResetImageROI(stitching_imgae);
cvSetImageROI(stitching_imgae, cvRect(0, front_left21.y, left_image->width, left_image->height));
cvAdd(left_image, stitching_imgae, stitching_imgae);
cvResetImageROI(stitching_imgae);
cvSetImageROI(stitching_imgae, cvRect(left_up21.x + front_image->width - (right_up21.x - right_up22.x), front_right21.y,
right_image->width, right_image->height));
cvAdd(right_image, stitching_imgae, stitching_imgae);
cvResetImageROI(stitching_imgae);
cvSetImageROI(stitching_imgae, cvRect(left_lower21.x, front_left21.y + left_image->height - (rear_left21.y - rear_left22.y),
rear_image->width, rear_image->height));
cvAdd(rear_image, stitching_imgae, stitching_imgae);
cvResetImageROI(stitching_imgae);
}
//剪切子函数
void cut_image()
{
int xx, yy;
//cut the left image
for (xx = 0; xx < left_image->width; ++xx) //cut the right_up corner
{
for (yy = 0; yy < left_image->height; ++yy)
{
if (yy < k1 *(xx - left_up21.x) +left_up21.y)
{
cvSet2D(left_image, yy, xx, cvScalar(0, 0, 0));
}
}
}
for (xx = 0; xx < left_image->width; ++xx) //cut the right_lower corner
{
for (yy = 0; yy < left_image->height; ++yy)
{
if (yy > k4 *(xx - left_lower21.x) +left_lower21.y)
{
cvSet2D(left_image, yy, xx, cvScalar(0, 0, 0));
}
}
}
//cut the right image
for (xx = 0; xx < right_image->width; ++xx)
{
for (yy = 0; yy < right_image->height; ++yy)
{
if (yy < k2 *(xx - right_up21.x) + right_up21.y)
{
cvSet2D(right_image, yy, xx, cvScalar(0, 0, 0));
}
}
}
for (xx = 0; xx < right_image->width; ++xx)
{
for (yy = 0; yy < right_image->height; ++yy)
{
if (yy > k3 *(xx - right_lower21.x) + right_lower21.y)
{
cvSet2D(right_image, yy, xx, cvScalar(0, 0, 0));
}
}
}
//cut the front image
for (xx = 0; xx < front_image->width; ++xx)
{
for (yy = 0; yy < front_image->height; ++yy)
{
if (yy > k1 *(xx - front_left21.x) + front_left21.y)
{
cvSet2D(front_image, yy, xx, cvScalar(0, 0, 0));
}
}
}
for (xx = 0; xx < front_image->width; ++xx)
{
for (yy = 0; yy < front_image->height; ++yy)
{
if (yy > k2 *(xx - front_right21.x) + front_right21.y)
{
cvSet2D(front_image, yy, xx, cvScalar(0, 0, 0));
}
}
}
//cut the rear image
for (xx = 0; xx < rear_image->width; ++xx)
{
for (yy = 0; yy < rear_image->height; ++yy)
{
if (yy < k4 *(xx - rear_left21.x) + rear_left21.y)
{
cvSet2D(rear_image, yy, xx, cvScalar(0, 0, 0));
}
}
}
for (xx = 0; xx < rear_image->width; ++xx)
{
for (yy = 0; yy < rear_image->height; ++yy)
{
if (yy < k3*(xx - rear_right21.x) + rear_right21.y)
{
cvSet2D(rear_image, yy, xx, cvScalar(0, 0, 0));
}
}
}
}
//计算剪切点
void calculate_cut_point()
{
k1 = ((float)left_up11.y - (float)left_up12.y)/((float)left_up11.x - (float)left_up12.x);
k2 = ((float)right_up11.y - (float)right_up12.y)/((float)right_up11.x - (float)right_up12.x);
k3 = ((float)right_lower11.y - (float)right_lower12.y)/((float)right_lower11.x - (float)right_lower12.x);
k4 = ((float)left_lower11.y - (float)left_lower12.y)/((float)left_lower11.x - (float)left_lower12.x);
left_up21.x = left_up11.x + (0 - left_up11.y)/k1;
left_up21.y = 0;
left_up22.x = left_image->width;
left_up22.y = left_up11.y + k1 * (left_image->width - left_up11.x);
left_lower21.x = left_lower11.x + (left_image->height - left_lower11.y)/k4;
left_lower21.y = left_image->height;
left_lower22.x = left_image->width;
left_lower22.y = left_lower11.y + k4 * (left_image->width - left_lower11.x);
right_up21.x = right_up11.x + (0 - right_up11.y)/k2;
right_up21.y = 0;
right_up22.x = 0;
right_up22.y = right_up11.y + k2 * (0 - right_up11.x);
right_lower21.x = right_lower11.x + (right_image->height - right_lower11.y)/k3;
right_lower21.y = right_image->height;
right_lower22.x = 0;
right_lower22.y = right_lower11.y + k3 * (0 - right_lower11.x);
front_left21.x = 0;
front_left21.y = front_left11.y + k1 * (0 - front_left11.x);
front_left22.x = front_left11.x + (front_image->height - front_left11.y)/k1;
front_left22.y = front_image->height;
front_right21.x = front_image->width;
front_right21.y = front_right11.y + k2 * (front_image->width - front_right11.x);
front_right22.x = front_right11.x + (front_image->height - front_right11.y)/k2;
front_right22.y = front_image->height;
rear_left21.x = 0;
rear_left21.y = rear_left11.y + k4 * (0 - rear_left11.x);
rear_left22.x = rear_left11.x + (0 - rear_left11.y)/k4;
rear_left22.y = 0;
rear_right21.x = rear_image->width;
rear_right21.y = rear_right11.y + k3 * (rear_image->width - rear_right11.x);
rear_right22.x = rear_right11.x + (0 - rear_right11.y)/k3;
rear_right22.y = 0;
}
//图像旋转
IplImage* rotate_image(IplImage* src, int angle)
{
IplImage* dst;
if (angle%180 == 0)
{
dst = cvCloneImage(src);
}
else
{
dst = cvCreateImage(cvSize(src->height, src->width), src->depth, src->nChannels);
}
float m[6];
CvMat M = cvMat( 2, 3, CV_32F, m );
int w = src->width;
int h = src->height;
m[0] = (float)(cos(-angle*CV_PI/180.));
m[1] = (float)(sin(-angle*CV_PI/180.));
m[2] = w*0.5f;
m[3] = -m[1];
m[4] = m[0];
m[5] = h*0.5f;
cvGetQuadrangleSubPix( src, dst, &M);
return dst;
}
//
void printf_point()
{
printf("%f , %f, %f, %f\n\n", k1, k2, k3, k4);
printf("(%d, %d) (%d, %d)\n", left_up11.x, left_up11.y, left_up12.x, left_up12.y);
printf("(%d, %d) (%d, %d)\n", left_lower11.x, left_lower11.y, left_lower12.x, left_lower12.y);
printf("(%d, %d) (%d, %d)\n", front_left11.x, front_left11.y, front_left12.x, front_left12.y);
printf("(%d, %d) (%d, %d)\n", front_right11.x, front_right11.y, front_right12.x, front_right12.y);
printf("(%d, %d) (%d, %d)\n", right_up11.x, right_up11.y, right_up12.x, right_up12.y);
printf("(%d, %d) (%d, %d)\n", right_lower11.x,right_lower11.y, right_lower12.x, right_lower12.y);
printf("(%d, %d) (%d, %d)\n", rear_left11.x, rear_left11.y, rear_left12.x, rear_left12.y);
printf("(%d, %d) (%d, %d)\n\n", rear_right11.x, rear_right11.y, rear_right12.x, rear_right12.y);
printf("(%d, %d) (%d, %d)\n", left_up21.x, left_up21.y, left_up22.x, left_up22.y);
printf("(%d, %d) (%d, %d)\n", left_lower21.x, left_lower21.y, left_lower22.x, left_lower22.y);
printf("(%d, %d) (%d, %d)\n", front_left21.x, front_left21.y, front_left22.x, front_left22.y);
printf("(%d, %d) (%d, %d)\n", front_right21.x, front_right21.y, front_right22.x, front_right22.y);
printf("(%d, %d) (%d, %d)\n", right_up21.x, right_up21.y, right_up22.x, right_up22.y);
printf("(%d, %d) (%d, %d)\n", right_lower21.x,right_lower21.y, right_lower22.x, right_lower22.y);
printf("(%d, %d) (%d, %d)\n", rear_left21.x, rear_left21.y, rear_left22.x, rear_left22.y);
printf("(%d, %d) (%d, %d)\n", rear_right21.x, rear_right21.y, rear_right22.x, rear_right22.y);
}