def render_tracks(self, frame, size, n=5, thick=True, radius=3): img_conn = ccore.Image(*size) img_split = ccore.Image(*size) if n < 0 or frame - n + 1 < self.start_frame: current = self.start_frame n = frame - current + 1 else: current = frame - n + 1 found = False for i in range(n): col = int(max(255. * (i + 1) / n, 255)) if current in self._frame_data: preframe = self.closest_preceding_frame(current) if preframe is not None: found = True for objIdP in self._frame_data[preframe]: nodeIdP = self.node_id(preframe, objIdP) objP = self.graph.node_data(nodeIdP) if self.graph.out_degree(nodeIdP) > 1: img = img_split else: img = img_conn for edgeId in self.graph.out_arcs(nodeIdP): nodeIdC = self.graph.tail(edgeId) objC = self.graph.node_data(nodeIdC) ccore.drawLine(ccore.Diff2D(*objP.oCenterAbs), ccore.Diff2D(*objC.oCenterAbs), img, col, thick=thick) ccore.drawFilledCircle( ccore.Diff2D(*objC.oCenterAbs), radius, img_conn, col) current += 1 if not found and frame in self._frame_data: for objId in self._frame_data[frame]: nodeId = self.node_id(frame, objId) obj = self.graph.node_data(nodeId) ccore.drawFilledCircle(ccore.Diff2D(*obj.oCenterAbs), radius, img_conn, col) return img_conn, img_split
def render(self, dctRenderInfo=None, images=None): lstImages = [] if not images is None: lstImages += images if dctRenderInfo is None: for name, oChannel in self._channel_registry.iteritems(): for strRegion, oContainer in oChannel.containers.iteritems(): strHexColor, fAlpha = oChannel.dctAreaRendering[strRegion] imgRaw = oChannel.meta_image.image imgCon = ccore.Image(imgRaw.width, imgRaw.height) ccore.drawContour(oContainer.getBinary(), imgCon, 255, False) lstImages.append((imgRaw, strHexColor, 1.0)) lstImages.append((imgCon, strHexColor, fAlpha)) else: for channel_name, dctChannelInfo in dctRenderInfo.iteritems(): if channel_name in self._channel_registry: oChannel = self._channel_registry[channel_name] if 'raw' in dctChannelInfo: strHexColor, fAlpha = dctChannelInfo['raw'] # special casing for virtual channel to mix # raw images together if oChannel.is_virtual(): lstImages.extend(oChannel.meta_images(fAlpha)) else: lstImages.append( (oChannel.meta_image.image, strHexColor, 1.0)) if 'contours' in dctChannelInfo: # transform the old dict-style to the new tuple-style, # which allows multiple definitions for one region if isinstance(dctChannelInfo['contours'], dict): lstContourInfos = [ (k, ) + v for k, v in dctChannelInfo['contours'].iteritems() ] else: lstContourInfos = dctChannelInfo['contours'] for tplData in lstContourInfos: strRegion, strNameOrColor, fAlpha, bShowLabels = tplData[: 4] # draw contours only if region is present if oChannel.has_region(strRegion): if len(tplData) > 4: bThickContours = tplData[4] else: bThickContours = False imgRaw = oChannel.meta_image.image if strNameOrColor == 'class_label': oContainer = oChannel.containers[strRegion] oRegion = oChannel.get_region(strRegion) dctLabels = {} dctColors = {} for iObjId, oObj in oRegion.iteritems(): iLabel = oObj.iLabel if not iLabel is None: if not iLabel in dctLabels: dctLabels[iLabel] = [] dctLabels[iLabel].append(iObjId) dctColors[ iLabel] = oObj.strHexColor imgCon2 = ccore.Image( imgRaw.width, imgRaw.height) for iLabel, lstObjIds in dctLabels.iteritems( ): imgCon = ccore.Image( imgRaw.width, imgRaw.height) # Flip this and use drawContours with fill option enables to get black background oContainer.drawContoursByIds( lstObjIds, 255, imgCon, bThickContours, False) lstImages.append( (imgCon, dctColors[iLabel], fAlpha)) if isinstance(bShowLabels, bool) and bShowLabels: oContainer.drawTextsByIds( lstObjIds, [str(iLabel)] * len(lstObjIds), imgCon2) lstImages.append((imgCon2, '#FFFFFF', 1.0)) else: oContainer = oChannel.containers[strRegion] oRegion = oChannel.get_region(strRegion) lstObjIds = oRegion.keys() imgCon = ccore.Image( imgRaw.width, imgRaw.height) if not strNameOrColor is None: oContainer.drawContoursByIds( lstObjIds, 255, imgCon, bThickContours, False) else: strNameOrColor = '#FFFFFF' lstImages.append( (imgCon, strNameOrColor, fAlpha)) if bShowLabels: imgCon2 = ccore.Image( imgRaw.width, imgRaw.height) oContainer.drawLabelsByIds( lstObjIds, imgCon2) lstImages.append( (imgCon2, '#FFFFFF', 1.0)) if len(lstImages) > 0: imgRgb = ccore.makeRGBImage( [x[0].getView() for x in lstImages], [ccore.RGBValue(*hex2rgb(x[1])) for x in lstImages], [x[2] for x in lstImages]) return imgRgb