def process(self, inframe, outframe): inimg = inframe.get() self.timer.start() imgbgr = jevois.convertToCvBGR(inimg) h, w, chans = imgbgr.shape outimg = outframe.get() outimg.require("output", w, h + 12, jevois.V4L2_PIX_FMT_YUYV) jevois.paste(inimg, outimg, 0, 0) jevois.drawFilledRect(outimg, 0, h, outimg.width, outimg.height - h, jevois.YUYV.Black) inframe.done() cube = self.detect(imgbgr, outimg) # Load camera calibration if needed: # if not hasattr(self, 'camMatrix'): self.loadCameraCalibration(w, h) if cube is not None: jevois.sendSerial(cube.toJson()) # Write frames/s info from our timer into the edge map (NOTE: does not account for output conversion time): fps = self.timer.stop() jevois.writeText(outimg, fps, 3, h - 10, jevois.YUYV.White, jevois.Font.Font6x10) outframe.send()
def process(self, inframe, outframe): jevois.LINFO("process with usb") # Get the next camera image (may block until it is captured): inimg = inframe.get() jevois.LINFO("Input image is {} {}x{}".format(jevois.fccstr(inimg.fmt), inimg.width, inimg.height)) # Get the next available USB output image: outimg = outframe.get() jevois.LINFO("Output image is {} {}x{}".format(jevois.fccstr(outimg.fmt), outimg.width, outimg.height)) # Example of getting pixel data from the input and copying to the output: jevois.paste(inimg, outimg, 0, 0) # We are done with the input image: inframe.done() # Example of in-place processing: jevois.hFlipYUYV(outimg) # Example of simple drawings: jevois.drawCircle(outimg, int(outimg.width/2), int(outimg.height/2), int(outimg.height/4), 2, jevois.YUYV.White) jevois.writeText(outimg, "Hi from Python - @MODULE@", 20, 20, jevois.YUYV.White, jevois.Font.Font10x20) # We are done with the output, ready to send it to host over USB: outframe.send() # Send a string over serial (e.g., to an Arduino). Remember to tell the JeVois Engine to display those messages, # as they are turned off by default. For example: 'setpar serout All' in the JeVois console: jevois.sendSerial("DONE frame {}".format(self.frame)); self.frame += 1
def process(self, inframe, outframe): # Get the next camera image (may block until it is captured). To avoid wasting much time assembling a composite # output image with multiple panels by concatenating numpy arrays, in this module we use raw YUYV images and # fast paste and draw operations provided by JeVois on those images: inimg = inframe.get() # Start measuring image processing time: self.timer.start() # Convert input image to BGR24: imgbgr = jevois.convertToCvBGR(inimg) h, w, chans = imgbgr.shape # Get pre-allocated but blank output image which we will send over USB: outimg = outframe.get() outimg.require("output", w * 2, h + 12, jevois.V4L2_PIX_FMT_YUYV) jevois.paste(inimg, outimg, 0, 0) jevois.drawFilledRect(outimg, 0, h, outimg.width, outimg.height - h, jevois.YUYV.Black) # Let camera know we are done using the input image: inframe.done() # Get a list of quadrilateral convex hulls for all good objects: hlist = self.detect(imgbgr, outimg) # Load camera calibration if needed: if not hasattr(self, 'camMatrix'): self.loadCameraCalibration(w, h) # Map to 6D (inverse perspective): (rvecs, tvecs) = self.estimatePose(hlist) # Send all serial messages: self.sendAllSerial(w, h, hlist, rvecs, tvecs) # Draw all detections in 3D: self.drawDetections(outimg, hlist, rvecs, tvecs) # Write frames/s info from our timer into the edge map (NOTE: does not account for output conversion time): fps = self.timer.stop() jevois.writeText(outimg, fps, 3, h - 10, jevois.YUYV.White, jevois.Font.Font6x10) # We are done with the output, ready to send it to host over USB: outframe.send()
def process(self, inframe, outframe): # Get the next camera image (may block until it is captured). To avoid wasting much time assembling a composite # output image with multiple panels by concatenating numpy arrays, in this module we use raw YUYV images and # fast paste and draw operations provided by JeVois on those images: inimg = inframe.get() # Start measuring image processing time: self.timer.start() # Convert input image to BGR24: imgbgr = jevois.convertToCvBGR(inimg) h, w, chans = imgbgr.shape # Get pre-allocated but blank output image which we will send over USB: outimg = outframe.get() outimg.require("output", w * 2, h + 12, jevois.V4L2_PIX_FMT_YUYV) #outimg.require("output", w, h + 12, jevois.V4L2_PIX_FMT_YUYV) jevois.paste(inimg, outimg, 0, 0) jevois.drawFilledRect(outimg, 0, h, outimg.width, outimg.height - h, jevois.YUYV.Black) # Let camera know we are done using the input image: inframe.done() # Get a list of quadrilateral convex hulls for all good objects: hlist = self.detect(imgbgr, outimg) # Load camera calibration if needed: if not hasattr(self, 'camMatrix'): self.loadCameraCalibration(w, h) # Map to 6D (inverse perspective): (rvecs, tvecs) = self.estimatePose(hlist) # Average Values for i in range(len(tvecs)): for k in range(len(tvecs[i])): self.tsum[k].append(tvecs[i][k]) while (len(self.tsum[k]) > 10): self.tsum[k].pop(0) for i in range(len(rvecs)): for k in range(len(rvecs[i])): self.rsum[k].append(rvecs[i][k]) while (len(self.rsum[k]) > 10): self.rsum[k].pop(0) # Find distance along ground to robot (Y) try: X = sum(self.tsum[0]) / len(self.tsum[0]) * self.mToFt Y = sum(self.tsum[2]) / len(self.tsum[2]) * self.mToFt Z = sum(self.tsum[1]) / len(self.tsum[1]) * self.mToFt groundDis = -0.2509 + 1.2073 * math.cos( self.cameraAngle - math.atan(Z / Y)) * math.sqrt(math.pow(Z, 2) + math.pow(Y, 2)) except: groundDis = 0 X = 0 Y = 0 Z = 0 # Output Average of Target in Feet and Radians jevois.writeText( outimg, "X: {} Y: {} Angle: {}".format( X, groundDis, (180 / 3.14) * sum(self.rsum[1]) / len(self.rsum[1])), 3, 0, jevois.YUYV.White, jevois.Font.Font6x10) # Send all serial messages: self.sendAllSerial(w, h, hlist, rvecs, tvecs) # Draw all detections in 3D: self.drawDetections(outimg, hlist, rvecs, tvecs) # Write frames/s info from our timer into the edge map (NOTE: does not account for output conversion time): fps = self.timer.stop() jevois.writeText(outimg, fps, 3, h - 10, jevois.YUYV.White, jevois.Font.Font6x10) # Test Serial Output #jevois.sendSerial("{} {}". # format(-1 * self.mToFt, -1 * self.mToFt)) # We are done with the output, ready to send it to host over USB: outframe.send()