@return Argument Parser object """ parser = argparse.ArgumentParser( description='Create a SensorModule for Yarp.') parser.add_argument('-n', '--name', dest='name', default='', help='Name prefix for Yarp port names') parser.add_argument( '-m', '--memory', dest='memory', type=type(0), default=0, help='Defines how long the marker positions are kept in memory.') parser.add_argument('-t', '--translation', dest='translation', default='', help='Give a file path to a translation file.') return parser.parse_args() if __name__ == '__main__': main(HCMarker, createArgParser())
@param cv2_image - an OpenCV image object """ # we only care for one contour gray = cv2.cvtColor(cv2_image, cv2.COLOR_RGB2GRAY) faces = OCFaceDetector.HC['frontalface_default'].detectMultiScale(gray, 1.3, 5) for (x, y, width, height) in faces: cv2.rectangle(cv2_image, (x, y), (x + width, y + height), (255, 0, 0), 2) roi_gray = gray[y:y + height, x:x + width] roi_color = cv2_image[y:y + height, x:x + width] eyes = OCFaceDetector.HC['eye'].detectMultiScale(roi_gray) for (e_x, e_y, e_width, e_height) in eyes: cv2.rectangle( roi_color, (e_x, e_y), (e_x + e_width, e_y + e_height), (0, 255, 0), 2 ) self.sendFaces(faces) self.sendPseudoSkeleton(faces) return cv2_image if __name__ == '__main__': main(OCFaceDetector)
The method detects faces and draws a bounding box around them on the output image. Afterwards the additional information is send to the corresponding ports. @param cv2_image - an OpenCV image object """ # we only care for one contour gray = cv2.cvtColor(cv2_image, cv2.COLOR_RGB2GRAY) faces = OCFaceDetector.HC['frontalface_default'].detectMultiScale( gray, 1.3, 5) for (x, y, width, height) in faces: cv2.rectangle(cv2_image, (x, y), (x + width, y + height), (255, 0, 0), 2) roi_gray = gray[y:y + height, x:x + width] roi_color = cv2_image[y:y + height, x:x + width] eyes = OCFaceDetector.HC['eye'].detectMultiScale(roi_gray) for (e_x, e_y, e_width, e_height) in eyes: cv2.rectangle(roi_color, (e_x, e_y), (e_x + e_width, e_y + e_height), (0, 255, 0), 2) self.sendFaces(faces) self.sendPseudoSkeleton(faces) return cv2_image if __name__ == '__main__': main(OCFaceDetector)
j_data = skeleton.data[joint] bottle.addString(label) _ = [ bottle.addDouble(value) for value in [j_data['POS'][-1]] + j_data['POS'][:3] ] bottle.addString("Orientation") bottle.addDouble(j_data['ORI'][-1]) _ = [ bottle.addDouble(value) for value in j_data['ORI_RM'].flatten() ] # pass the time value as first element in the envelop ebottle = yarp.Bottle() ebottle.clear() ebottle.addDouble(envelope_bottle.get(1).asDouble()) self.skeletonOutPort.setEnvelope(ebottle) self.skeletonOutPort.write(bottle) def respond(self, command, reply): return True if __name__ == '__main__': main(TSUserSkeleton)
reply.addString("ack" if success else "nack") return True def createArgParser(): """ This method creates a base argument parser. @return Argument Parser object """ parser = argparse.ArgumentParser(description="Create a SensorModule for Yarp.") parser.add_argument("-n", "--name", dest="name", default="", help="Name prefix for Yarp port names") parser.add_argument( "-m", "--memory", dest="memory", type=type(0), default=0, help="Defines how long the marker positions are kept in memory.", ) parser.add_argument( "-t", "--translation", dest="translation", default="", help="Give a file path to a translation file." ) return parser.parse_args() if __name__ == "__main__": main(HCMarker, createArgParser())
skeleton = data[key] bottle = yarp.Bottle() bottle.clear() for joint, label in TSUserSkeleton.USED_JOINTS.items(): j_data = skeleton.data[joint] bottle.addString(label) _ = [bottle.addDouble(value) for value in [j_data['POS'][-1]] + j_data['POS'][:3]] bottle.addString("Orientation") bottle.addDouble(j_data['ORI'][-1]) _ = [bottle.addDouble(value) for value in j_data['ORI_RM'].flatten()] # pass the time value as first element in the envelop ebottle = yarp.Bottle() ebottle.clear() ebottle.addDouble(envelope_bottle.get(1).asDouble()) self.skeletonOutPort.setEnvelope(ebottle) self.skeletonOutPort.write(bottle) def respond(self, command, reply): return True if __name__ == '__main__': main(TSUserSkeleton)