def getImageWithVideo(self, num): video = Video() filename = self.testMedia + "chessBoard%03d.jpg" % (num) image = video.readImage(filename) height, width = image.shape[:2] print ("read image %s: %dx%d" % (filename, width, height)) return image,video
def test_getSubRect(self): video = Video() image = video.readImage(testenv.testMedia+"chessBoard001.jpg") subImage = Video.getSubRect(image, (0, 0, 200, 200)) iheight, iwidth, channels = subImage.shape assert iheight == 200 assert iwidth == 200 assert channels == 3
def __init__(self, image, video=None): """ construct me from the given input image""" if video is None: video = Video() self.video = video self.image = image # guess the topleft color self.topleft = chess.WHITE self.height, self.width = self.image.shape[:2]
def getVideo(self) -> Video: ''' get a Video (potentially headless) Returns: Video: the video handler for openCV ''' video = Video() video.headless = self.headless return video
def test_CreateBlank(self): video = Video() width = 400 height = 400 image = video.createBlank(width, height) iheight, iwidth, channels = image.shape print ("created blank %dx%d image with %d channels" % (iwidth, iheight, channels)) assert height == iheight assert width == iwidth assert channels == 3
def test_ReadJpg(self): video = Video() video.open(testenv.testMedia+'emptyBoard001.avi') for frame in range(0, 52): ret, jpgImage, quit = video.readFrame(show=True) assert ret assert jpgImage is not None height, width = jpgImage.shape[:2] # print ("%d: %d x %d" % (frame,width,height)) assert (width, height) == (640, 480) assert video.frames == 52
def test_Concatenate(self): video=Video() w=400 h=400 #https://stackoverflow.com/a/21170291/1497139 image1=video.createBlank(w, h, (192,192,192)) image2=video.createBlank(w, h, (255,128,0)) image3=video.createBlank(w, h, (255//3,255//3,255/3)) image4=video.createBlank(w, h, (0,0,255)) combined=video.as2x2(image1,image2,image3,image4,downScale=1) hc, wc= combined.shape[:2] assert hc==2*h assert wc==2*w video.showImage(combined, "combined",keyWait=1000)
def test_ReadVideoWithPause(self): video = Video() video.open(testenv.testMedia+'emptyBoard001.avi') for frame in range(0, 62): if frame >= 10 and frame < 20: video.pause(True) else: video.pause(False) ret, jpgImage, quit = video.readFrame(show=True) # print (video.frames) assert ret assert jpgImage is not None height, width = jpgImage.shape[:2] # print ("%d: %d x %d" % (frame,width,height)) assert (width, height) == (640, 480) assert video.frames == 52
def setup(self, idealSize=640, video=None): # video access (for debugging and partly hiding open cv details) if video is None: self.video = Video() self.idealSize = idealSize s = idealSize self.pts_IdealSquare = np.asarray( [[0.0, 0.0], [s, 0.0], [s, s], [0.0, s]], dtype=np.float32) self.inverseTransform = cv2.getPerspectiveTransform( self.pts_dst, self.pts_IdealSquare) self.rotation = 0 # dict for average Colors self.averageColors = {} self.diffSumAverage = MovingAverage( ChessTrapezoid.DiffSumMovingAverageLength) # trapezoid representation of squares self.tsquares = {} for square in chess.SQUARES: tsquare = ChessTSquare(self, square) if ChessTrapezoid.debug: print(vars(tsquare)) self.tsquares[tsquare.square] = tsquare
def __init__(self,args,board=None): self.device=args.input self.title=Video.title(self.device) self.video=Video(self.title) self.args=args self.showDebug=args.debug self.start=None self.quitWanted=False self.hasImage=False self.timestamps=[] self.debug=args.debug if board is None: board=Board(args=args) self.board = board if self.args.fen is not None: self.board.updatePieces(self.args.fen) self.warp = Warp(args.warpPointList) self.warp.rotation = args.rotation if self.args.nowarp: self.warp.warping=True self.firstFrame=True self.speedup=args.speedup pass
def home(self): self.videoAnalyzer.vision.video = Video() return self.index("Home")
def showDebug(self, video=None, keyWait=5): if video is None: video = Video() video.showImage(self.image, self.title, keyWait=keyWait)
def test_ReadVideo(self): video = Video() video.open(testenv.testMedia+'emptyBoard001.avi') video.play() print ("played %d frames" % (video.frames)) assert video.frames == 52
def test_ReadVideoWithPostProcess(self): video = Video() video.open(testenv.testMedia+'emptyBoard001.avi') for frame in range(0, 52): ret, jpgImage, quit = video.readFrame(show=True, postProcess=video.addTimeStamp)