void Composite(Magick::Image& canv_img, const Magick::Image& obj_img, FrameThemeObj& fto) { Magick::Image img; Rect mdPlc = fto.Placement(); Point sz = mdPlc.Size(); ZoomImage(img, obj_img, sz.x, sz.y); // сначала скопируем маску в изображение, // которое накладываем, используя опять же composite(CopyOpacityCompositeOp) // 1 включаем прозрачность img.matte(true); // 2 копируем прозрачность с рамки img.composite(VFrameImg(fto), 0, 0, MagickLib::CopyOpacityCompositeOp); // 3 накладываем результат c альфа-блэндингом (OverCompositeOp) canv_img.composite(FrameImg(fto), mdPlc.lft, mdPlc.top, MagickLib::OverCompositeOp); canv_img.composite(img, mdPlc.lft, mdPlc.top, MagickLib::OverCompositeOp); }
static XImage *generateZoomImages(int maxzoom) { int i; for (i = 1; i < MAXZOOM; i++){ if (!Images[i-1]) continue; Image = Images[i] = ZoomImage(Images[i-1]); if(Image == NULL){// out of memory Image = Images[i -1]; break; } } i = maxzoom; while (!Images[i]) i--; return Images[i]; }
void CImageProcess::ZoomImage(vector<Image> *in, vector<Image> *out, Location &zoo) { for(int i=0; i<in->size(); i++){ char c[10]; itoa(i+10, c, 10); Image zootmp; zootmp._width = zoo._start - 2; zootmp._height = zoo._end - 2; zootmp._pData = new unsigned char[zootmp._width * zootmp._height]; memset(zootmp._pData, 0, zootmp._width * zootmp._height); ZoomImage(in->at(i), zootmp); Image dsttmp; dsttmp._width = zoo._start; dsttmp._height = zoo._end; dsttmp._pData = new unsigned char[dsttmp._width * dsttmp._height]; FillImage(zootmp, dsttmp); delete []zootmp._pData; out->push_back(dsttmp); IplImage *img = CreateImage(dsttmp, c); } }
Export Image *MontageImages(const Image *images,const MontageInfo *montage_info) { #define MontageImageText " Creating visual image directory... " #define TileImageText " Creating image tiles... " AnnotateInfo *annotate_info; char geometry[MaxTextExtent]; FrameInfo frame_info; Image *image, **image_list, **master_list, *montage_image, *texture, *tiled_image; ImageInfo *local_info; int x, x_offset, y, y_offset; MonitorHandler handler; register int i; register PixelPacket *q; RectangleInfo bounding_box, tile_info; unsigned int border_width, bevel_width, concatenate, count, font_height, height, images_per_page, max_height, number_images, number_lines, tile, tiles, tiles_per_column, tiles_per_row, tiles_per_page, title_offset, total_tiles, width; assert(images != (Image *) NULL); assert(montage_info != (MontageInfo *) NULL); /* Convert image list to an image group. */ image_list=ListToGroupImage(images,&number_images); if (image_list == (Image **) NULL) { MagickWarning(ResourceLimitWarning,"Unable to montage image_list", "Memory allocation failed"); return((Image *) NULL); } master_list=image_list; /* Create image tiles. */ for (tile=0; tile < number_images; tile++) { handler=SetMonitorHandler((MonitorHandler) NULL); width=image_list[tile]->columns; height=image_list[tile]->rows; x=0; y=0; (void) ParseImageGeometry(montage_info->geometry,&x,&y,&width,&height); image_list[tile]->orphan=True; tiled_image=ZoomImage(image_list[tile],width,height); if (tiled_image == (Image *) NULL) { for (i=0; i < (int) tile; i++) DestroyImage(image_list[i]); (void) SetMonitorHandler(handler); return((Image *) NULL); } image_list[tile]=tiled_image; (void) SetMonitorHandler(handler); ProgressMonitor(TileImageText,tile,number_images); } /* Sort image_list by increasing tile number. */ for (tile=0; tile < number_images; tile++) if (image_list[tile]->scene == 0) break; if (tile == number_images) qsort((void *) image_list,number_images,sizeof(Image *), (int (*)(const void *, const void *)) SceneCompare); /* Determine tiles per row and column. */ tiles_per_row=1; tiles_per_column=1; while ((tiles_per_row*tiles_per_column) < number_images) { tiles_per_row++; tiles_per_column++; } if (montage_info->tile != (char *) NULL) { tiles_per_column=number_images; x=0; y=0; (void) ParseGeometry(montage_info->tile,&x,&y,&tiles_per_row, &tiles_per_column); } /* Determine tile sizes. */ border_width=montage_info->border_width; bevel_width=0; if (montage_info->frame != (char *) NULL) { int flags; frame_info.width=0; frame_info.height=0; frame_info.outer_bevel=0; frame_info.inner_bevel=0; flags=ParseGeometry(montage_info->frame,&frame_info.outer_bevel, &frame_info.inner_bevel,&frame_info.width,&frame_info.height); if ((flags & HeightValue) == 0) frame_info.height=frame_info.width; if ((flags & XValue) == 0) frame_info.outer_bevel=(frame_info.width >> 2)+1; if ((flags & YValue) == 0) frame_info.inner_bevel=frame_info.outer_bevel; frame_info.x=frame_info.width; frame_info.y=frame_info.height; bevel_width=Max(frame_info.inner_bevel,frame_info.outer_bevel); border_width=Max(frame_info.width,frame_info.height); }
void CImageProcess::ProcessImage() { IplImage* pOSource = cvLoadImage(m_sName.c_str()); m_mapImage.insert(std::pair<string, IplImage*>(m_sName, pOSource)); //opencv 灰度化 IplImage* pOGray = cvCreateImage(cvGetSize(pOSource), IPL_DEPTH_8U, 1); m_mapImage.insert(std::pair<string, IplImage*>("gray", pOGray)); cvCvtColor(pOSource, pOGray, CV_BGR2GRAY); //opencv 二值化 IplImage* pOBinary = cvCreateImage(cvGetSize(pOGray), IPL_DEPTH_8U, 1); m_mapImage.insert(std::pair<string, IplImage*>("binary", pOBinary)); cvThreshold(pOGray, pOBinary, 175, 255, CV_THRESH_BINARY); //pSwellTemp = LevelSwell(pOBinary->imageData, pOBinary->widthStep, pOBinary->height,8); //VerticalSwell(pOBinary->imageData, pOBinary->widthStep, pOBinary->height, 0); //OpencvSwell(pOBinary, pOBinary); //投影法,分割 unsigned int *pVHist = new unsigned int[pOBinary->widthStep]; VerticalProjection(pOBinary->imageData, pOBinary->widthStep, pOBinary->height, pVHist); unsigned int *pHHist = new unsigned int[pOBinary->height]; HorizontalProjection(pOBinary->imageData, pOBinary->widthStep, pOBinary->height, pHHist); vector<Location> v_lc = Projection_Location(pVHist,pOBinary->widthStep, pOBinary->height); vector<Location> h_lc = Projection_Location(pHHist,pOBinary->height, pOBinary->widthStep); //切图 Image image; image._height = pOBinary->height; image._width = pOBinary->widthStep; image._pData = new unsigned char[image._height * image._width]; memset(image._pData, 0 , image._height * image._width); memcpy_s(image._pData, image._height * image._width, pOBinary->imageData, image._height * image._width); vector<Image> dst; CutImage(image, v_lc, h_lc, &dst); delete []image._pData; //缩放 //Location l = FindMaxLocation(v_lc, h_lc); Location l; l._start = 16; l._end = 16; vector<Image> zImage; ZoomImage(&dst,&zImage, l); //提取特征 for(int i=0; i<zImage.size(); i++){ char c[10]; itoa(i, c, 10); IplImage *img = CreateImage(zImage.at(i)); //m_mapImage.insert(std::pair<string, IplImage*>(c, img)); SIFTInstance(img, c); ReleaseUserImage(&img); } /* char* cOTitle = {"opencv"}; cvNamedWindow(cOTitle, CV_WINDOW_AUTOSIZE); cvShowImage(cOTitle,pOBinary);*/ //test(); cvWaitKey(); cvDestroyAllWindows(); }