def rotate(im, angle): center = (im.width / 2.0, im.height / 2.0) mat = cv.CreateMat(2, 3, cv.CV_32FC1) cv.GetRotationMatrix2D(center, angle, 1.0, mat) out = cv.CreateImage(cv.GetSize(im), cv.IPL_DEPTH_8U, 1) cv.WarpAffine(im, out, mat, fillval=255) return out
def img(self): '''return a cv image for the icon''' SlipThumbnail.img(self) if self.rotation: # rotate the image mat = cv.CreateMat(2, 3, cv.CV_32FC1) cv.GetRotationMatrix2D((self.width / 2, self.height / 2), -self.rotation, 1.0, mat) self._rotated = cv.CloneImage(self._img) cv.WarpAffine(self._img, self._rotated, mat) else: self._rotated = self._img return self._rotated
r = 28 + j * 4 mr = r * math.sqrt(2) y += mr * 1.8 test += [(str(deg) + "abcdefgh"[j], (50 + deg * 11, y), math.pi * deg / 180, r) for deg in range(0, 90, 10)] for (msg, (x, y), angle, r) in test: map = cv.CreateMat(2, 3, cv.CV_32FC1) corners = [(x + r * math.cos(angle + th), y + r * math.sin(angle + th)) for th in [0, math.pi / 2, math.pi, 3 * math.pi / 4]] src = mkdmtx(msg) (sx, sy) = cv.GetSize(src) cv.GetAffineTransform([(0, 0), (sx, 0), (sx, sy)], corners[:3], map) temp = cv.CreateMat(bg.rows, bg.cols, cv.CV_8UC3) cv.Set(temp, cv.RGB(0, 0, 0)) cv.WarpAffine(src, temp, map) cv.Or(temp, bg, bg) cv.ShowImage("comp", bg) scribble = cv.CloneMat(bg) if 0: for i in range(10): df.find(bg) for (sym, coords) in df.find(bg).items(): print sym cv.PolyLine(scribble, [coords], 1, cv.CV_RGB(255, 0, 0), 1,
def _wipeMix(self, wipeMode, wipeConfig, level, image1, image2, mixMat): if((wipeMode == WipeMode.Push)): wipeDirection = wipeConfig if(wipeDirection < 0.25): wipePosX = int(self._internalResolutionX * level) sourceLeft = self._internalResolutionX-wipePosX sourceTop = 0 sourceWidth = wipePosX sourceHeight = self._internalResolutionY destLeft = 0 destTop = 0 elif(wipeDirection < 0.5): wipePosX = self._internalResolutionX - int(self._internalResolutionX * level) sourceLeft = 0 sourceTop = 0 sourceWidth = self._internalResolutionX-wipePosX sourceHeight = self._internalResolutionY destLeft = self._internalResolutionX-(self._internalResolutionX-wipePosX) destTop = 0 elif(wipeDirection < 0.75): wipePosY = int(self._internalResolutionY * level) sourceLeft = 0 sourceTop = self._internalResolutionY-wipePosY sourceWidth = self._internalResolutionX sourceHeight = wipePosY destLeft = 0 destTop = 0 else: wipePosY = self._internalResolutionY - int(self._internalResolutionY * level) sourceLeft = 0 sourceTop = 0 sourceWidth = self._internalResolutionX sourceHeight = self._internalResolutionY-wipePosY destLeft = 0 destTop = self._internalResolutionY-(self._internalResolutionY-wipePosY) destWidth = sourceWidth destHeight = sourceHeight src_region = cv.GetSubRect(image2, (sourceLeft, sourceTop, sourceWidth, sourceHeight)) if(image1 == None): cv.SetZero(mixMat) dst_region = cv.GetSubRect(mixMat, (destLeft, destTop, destWidth, destHeight)) return mixMat else: dst_region = cv.GetSubRect(mixMat, (destLeft, destTop, destWidth, destHeight)) cv.Copy(src_region, dst_region) if(wipeDirection < 0.25): wipePosX = int(self._internalResolutionX * level) sourceLeft = wipePosX sourceTop = 0 sourceWidth = self._internalResolutionX-wipePosX sourceHeight = self._internalResolutionY destLeft = wipePosX destTop = 0 elif(wipeDirection < 0.5): wipePosX = self._internalResolutionX - int(self._internalResolutionX * level) sourceLeft = 0 sourceTop = 0 sourceWidth = wipePosX sourceHeight = self._internalResolutionY destLeft = 0 destTop = 0 elif(wipeDirection < 0.75): wipePosY = int(self._internalResolutionY * level) sourceLeft = 0 sourceTop = wipePosY sourceWidth = self._internalResolutionX sourceHeight = self._internalResolutionY-wipePosY destLeft = 0 destTop = wipePosY else: wipePosY = self._internalResolutionY - int(self._internalResolutionY * level) sourceLeft = 0 sourceTop = 0 sourceWidth = self._internalResolutionX sourceHeight = wipePosY destLeft = 0 destTop = 0 destWidth = sourceWidth destHeight = sourceHeight src_region = cv.GetSubRect(image1, (sourceLeft, sourceTop, sourceWidth, sourceHeight)) dst_region = cv.GetSubRect(mixMat, (destLeft, destTop, destWidth, destHeight)) cv.Copy(src_region, dst_region) return mixMat if(wipeMode == WipeMode.Noize): scaleArg = wipeConfig noizeMask = getNoizeMask(level, self._internalResolutionX, self._internalResolutionY, 1.0 + (19.0 * scaleArg)) if(image1 == None): cv.SetZero(mixMat) cv.Copy(image2, mixMat, noizeMask) return mixMat cv.Copy(image2, image1, noizeMask) return image1 if(wipeMode == WipeMode.Zoom): xMove, yMove = wipeConfig xSize = int(self._internalResolutionX * level) ySize = int(self._internalResolutionY * level) xPos = int((self._internalResolutionX - xSize) * xMove) yPos = int((self._internalResolutionY - ySize) * (1.0 - yMove)) cv.SetZero(mixMat) dst_region = cv.GetSubRect(mixMat, (xPos, yPos, xSize, ySize)) cv.Resize(image2, dst_region,cv.CV_INTER_CUBIC) if(image1 == None): return mixMat cv.SetZero(self._mixMixMask1) dst_region = cv.GetSubRect(self._mixMixMask1, (xPos, yPos, xSize, ySize)) cv.Set(dst_region, 256) cv.Copy(mixMat, image1, self._mixMixMask1) return image1 if(wipeMode == WipeMode.Flip): flipRotation = wipeConfig rotation = 1.0 - level srcPoints = ((0.0, 0.0),(0.0,self._internalResolutionY),(self._internalResolutionX, 0.0)) destPoint1 = (0.0, 0.0) destPoint2 = (0.0, self._internalResolutionY) destPoint3 = (self._internalResolutionX, 0.0) if(image1 == None): rotation = rotation / 2 if(rotation < 0.5): flipAngle = rotation / 2 else: flipAngle = level / 2 destPoint1 = rotatePoint(flipRotation, destPoint1[0], destPoint1[1], self._halfResolutionX, self._halfResolutionY, flipAngle) destPoint2 = rotatePoint(flipRotation, destPoint2[0], destPoint2[1], self._halfResolutionX, self._halfResolutionY, flipAngle) destPoint3 = rotatePoint(flipRotation, destPoint3[0], destPoint3[1], self._halfResolutionX, self._halfResolutionY, flipAngle) dstPoints = ((destPoint1[0], destPoint1[1]),(destPoint2[0], destPoint2[1]),(destPoint3[0],destPoint3[1])) zoomMatrix = cv.CreateMat(2,3,cv.CV_32F) # print "DEBUG pcn: trasform points source: " + str(srcPoints) + " dest: " + str(dstPoints) cv.GetAffineTransform(srcPoints, dstPoints, zoomMatrix) if(rotation < 0.5): cv.WarpAffine(image2, mixMat, zoomMatrix) else: cv.WarpAffine(image1, mixMat, zoomMatrix) cv.Set(self._mixMixMask2, (255,255,255)) cv.WarpAffine(self._mixMixMask2, self._mixMixMask1, zoomMatrix) return mixMat return image2