// Сглаживание контуров, исключение артефактов. int smoothContour(frGeomStrip* src){ if ( src->edgeA.size() != src->edgeB.size() ){ return 0; } // сгладить applySmooth(src); // отрезать ролики if( vertical ) applyDisRoller(src); // перестроить центральную линию calculateCenter(src); return 0; }
int main(int argc, char *argv[]) { int numtasks, rank, rc, dest, source, count, tag=1; int number_of_processes; char inmsg[10], outmsg[10]; // original image IplImage* img = 0; uchar *img_local_data = 0; if(argc<2) { printf("Usage: main <image-file-name>\n\7"); exit(0); } // load an image // Initialize MPI and get important variable. MPI_Status Stat; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &number_of_processes); img=cvLoadImage(argv[1], CV_LOAD_IMAGE_COLOR); if(!img) { printf("Could not load image file: %s\n",argv[1]); exit(0); } // Image size int imageSize = img->height*img->widthStep; // Calculates the amount of work of each process int workload = img->height / number_of_processes; int rec_size = workload * img->widthStep; if(rank == 0) { // Array that contains the final imageData char *result = malloc(rec_size); char *extra = 0; int total_work = workload * number_of_processes; // The first process always calculates the first part of the matrix applySmooth(img, result, 0, workload); if (total_work < img->height) { extra = malloc((img->height - total_work) * img->widthStep); applySmooth(img, extra, total_work, img->height); memcpy(img->imageData + rec_size * number_of_processes, extra, (img->height - total_work) * img->widthStep); } // Collect all the processed data MPI_Gather(result, rec_size, MPI_CHAR, img->imageData, rec_size, MPI_CHAR, 0, MPI_COMM_WORLD); cvSaveImage("result/result.jpg", img, 0); cvReleaseImage(&img); } else { // Each process knows where to start int start = rank*workload; char * result = malloc(rec_size); applySmooth(img, result, start, start+workload); // The offset is important to avoid any problems while building the // image MPI_Gather(result, rec_size, MPI_CHAR, NULL , rec_size, MPI_CHAR, 0, MPI_COMM_WORLD); } MPI_Finalize(); return 0; }