class Ludan(): img = None # keep image data from C langauge _fast_rcnn = None ''' C invokes the sendImge() to send a image from C to Python ''' def sendImg(self, frame, height, width, channels): self.img = np.frombuffer(frame, np.uint8) self.img = np.reshape(self.img, (height, width, channels)) print self.img.shape return 110, 50, 600, 50 ''' C invokes the showImge() to show a image which has been sent by sendImg ''' def showImg(self): print self.img.shape cv2.imshow('ShowImg', self.img) """ while True: cv2.imshow('showImg', self.img) k = 0xFF & cv2.waitKey(30) # key bindings if k == 27: # esc to exit break """ return 'Hi Ludan' def call_fast_rcnn_frame(self, frame, height, width, channels): #print 'Call Fast-RCNN Frame -> height: {} width: {} channels: {}'.format(height, width, channels) #print type(frame) #img = np.frombuffer(frame, np.uint8) img = np.reshape(frame, (height, width, channels)) print 'Detect object from C -> reshape: {}'.format(img.shape) #Create Fast_RCNN C Interface if self._fast_rcnn is None: self._fast_rcnn = Fast_RCNN_C_Interface() # Run Fast-RCNN hand5_max_detection = self._fast_rcnn.detect_object(img) print 'HAND5 MAX DETECTION IS: {}'.format(hand5_max_detection) return hand5_max_detection
if cap is None or not cap.isOpened(): print 'Warning: unable to open video source: video0' sys.exit() #Create Fast_RCNN C Interface fast_rcnn = Fast_RCNN_C_Interface() #Get Camera Image while True: #Read Image ret, img = cap.read() #Detect Object and Show FPS timer = Timer() timer.tic() # Run Fast-RCNN hand5_max_detection = fast_rcnn.detect_object(img) print 'HAND5 MAX DETECTION IS: {}'.format(hand5_max_detection) timer.toc() print 'Detection took {:.3f}s for ONE IMAGE !! '.format(timer.total_time) #Draw the Biggest Rectangle if not (hand5_max_detection[0] is 0 and hand5_max_detection[1] is 0 and hand5_max_detection[2] is 0 and hand5_max_detection[3] is 0): #Draw the Rectangle cv2.rectangle(img, (hand5_max_detection[0], hand5_max_detection[1]), (hand5_max_detection[2], hand5_max_detection[3]), (0, 255, 0), 3) #Show Image cv2.imshow('Detect Result', img) cv2.waitKey(30) #Release OpenCV reSource