def CompositeThumbnail(img, regions, thumb_size=100): '''extract a composite thumbnail for the regions of an image The composite will consist of N thumbnails side by side ''' composite = cv.CreateImage((thumb_size*len(regions), thumb_size),8,3) for i in range(len(regions)): (x1,y1,x2,y2) = regions[i].tuple() midx = (x1+x2)/2 midy = (y1+y2)/2 if (x2-x1) > thumb_size or (y2-y1) > thumb_size: # we need to shrink the region rsize = max(x2+1-x1, y2+1-y1) src = cuav_util.SubImage(img, (midx-rsize/2,midy-rsize/2,rsize,rsize)) thumb = cv.CreateImage((thumb_size, thumb_size),8,3) cv.Resize(src, thumb) else: x1 = midx - thumb_size/2 y1 = midy - thumb_size/2 thumb = cuav_util.SubImage(img, (x1, y1, thumb_size, thumb_size)) cv.SetImageROI(composite, (thumb_size*i, 0, thumb_size, thumb_size)) cv.Copy(thumb, composite) cv.ResetImageROI(composite) return composite
def CompositeThumbnail(img, regions, thumb_size=100): '''extract a composite thumbnail for the regions of an image The composite will consist of N thumbnails side by side ''' composite = [] for i in range(len(regions)): (x1, y1, x2, y2) = regions[i].tuple() midx = (x1 + x2) / 2 midy = (y1 + y2) / 2 if (x2 - x1) > thumb_size or (y2 - y1) > thumb_size: # we need to shrink the region rsize = max(x2 + 1 - x1, y2 + 1 - y1) src = cuav_util.SubImage( img, (midx - rsize / 2, midy - rsize / 2, rsize, rsize)) thumb = cv2.resize(src, (thumb_size, thumb_size)) else: x1 = midx - thumb_size / 2 y1 = midy - thumb_size / 2 thumb = cuav_util.SubImage(img, (x1, y1, thumb_size, thumb_size)) if composite == []: composite = thumb else: composite = numpy.concatenate((composite, thumb), axis=1) return composite
def CompositeThumbnail(img, regions, thumb_size=100): '''extract a composite thumbnail for the regions of an image The composite will consist of N thumbnails side by side ''' composite = cv.CreateImage((thumb_size * len(regions), thumb_size), 8, 3) x0 = y0 = 0 for i, r in enumerate(regions): (x1, y1, x2, y2) = r.tuple() midx = (x1 + x2) / 2 midy = (y1 + y2) / 2 if (x2 - x1) > thumb_size or (y2 - y1) > thumb_size: # we need to shrink the region rsize = max(x2 + 1 - x1, y2 + 1 - y1) src = cuav_util.SubImage( img, (midx - rsize / 2, midy - rsize / 2, rsize, rsize)) thumb = cv.CreateImage((thumb_size, thumb_size), 8, 3) cv.Resize(src, thumb) else: if x1 > x0 and x1 < x0 + thumb_size and y1 > y0 and y1 < y0 + thumb_size: r.dupe = True continue x1 = midx - thumb_size / 2 y1 = midy - thumb_size / 2 x0 = x1 y0 = y1 thumb = cuav_util.SubImage(img, (x1, y1, thumb_size, thumb_size)) cv.SetImageROI(composite, (thumb_size * i, 0, thumb_size, thumb_size)) cv.Copy(thumb, composite) cv.ResetImageROI(composite) return composite
def ExtractThumbs(img, count): '''extract thumbnails from a composite thumbnail image''' thumb_size = cuav_util.image_width(img) / count thumbs = [] for i in range(count): thumb = cuav_util.SubImage(img, (i*thumb_size, 0, thumb_size, thumb_size)) thumbs.append(thumb) return thumbs
def add_regions(self, regions, thumbs, filename, pos=None): '''add some regions''' for i in range(len(regions)): r = regions[i] (x1, y1, x2, y2) = r.tuple() latlon = r.latlon if latlon is None: latlon = (None, None) (lat, lon) = latlon if self.boundary: if (lat, lon) == (None, None): # its pointing into the sky continue # if cuav_util.polygon_outside((lat,lon), self.boundary): # # this region is outside the search boundary # continue # the thumbnail we have been given will be bigger than the size we want to # display on the mosaic. Extract the middle of it for display full_thumb = thumbs[i] rsize = max(x2 + 1 - x1, y2 + 1 - y1) tsize = cuav_util.image_width(full_thumb) if rsize < tsize: thumb = cuav_util.SubImage(full_thumb, ((tsize - self.thumb_size) // 2, (tsize - self.thumb_size) // 2, self.thumb_size, self.thumb_size)) else: thumb = cv.CreateImage((self.thumb_size, self.thumb_size), 8, 3) cv.Resize(full_thumb, thumb) ridx = len(self.regions) self.regions.append( MosaicRegion(ridx, r, filename, pos, thumbs[i], thumb, latlon=(lat, lon))) self.regions_sorted.append(self.regions[-1]) self.display_mosaic_region(ridx) if (lat, lon) != (None, None): self.slipmap.add_object( mp_slipmap.SlipThumbnail("region %u" % ridx, (lat, lon), img=thumb, layer=2, border_width=1, border_colour=(255, 0, 0), popup_menu=self.popup_menu)) self.image_mosaic.set_image(self.mosaic, bgr=True)
def make_thumb(self, full, r, size): (x1, y1, x2, y2) = r.tuple() rsize = max(x2 + 1 - x1, y2 + 1 - y1) tsize = cuav_util.image_width(full) if rsize < tsize: thumb = cuav_util.SubImage(full, ((tsize - size) // 2, (tsize - size) // 2, size, size)) else: thumb = cv2.resize(full, (size, size)) return thumb