def videoFrame1(self, image): self.cv_image = self.cv.imgmsg_to_cv2(image, "rgb8") self.cv_image = cv2.cvtColor(self.cv_image, cv2.COLOR_BGR2RGB) self.cv_image = cv2.resize(self.cv_image, (self.cv_image.shape[1]/2, self.cv_image.shape[0]/2)) lab_img, cont_image, center_mass, cont_area = find_car(self.cv_image, self.trackingColor, self.hsThreshold.value()/100.0) self.cv_image = find_rectangles(self.cv_image) qi = QImage(cont_image.data, cont_image.shape[1], cont_image.shape[0], QImage.Format_RGB888).rgbSwapped() self.lbVideo1.setFixedHeight(cont_image.shape[0]) self.lbVideo1.setFixedWidth(cont_image.shape[1]) self.lbVideo1.setPixmap(QPixmap.fromImage(qi))
def videoFrame(self, image): self.cv_image = self.cv.imgmsg_to_cv2(image, "rgb8") self.cv_image = cv2.resize(self.cv_image, (self.cv_image.shape[1]/2, self.cv_image.shape[0]/2)) # self._pr.enable() lab_img, cont_image, center_mass, cont_area = find_car(self.cv_image, self.trackingColor, self.hsThreshold.value()/100.0) # self._pr.disable() # self._pr.print_stats('cumtime') qi = QImage(cont_image.data, cont_image.shape[1], cont_image.shape[0], QImage.Format_RGB888) self.lbVideo.setFixedHeight(cont_image.shape[0]) self.lbVideo.setFixedWidth(cont_image.shape[1]) self.lbVideo.setPixmap(QPixmap.fromImage(qi)) x_center = center_mass[0] y_center = center_mass[1] if self.cbAuto.isChecked(): self.fly(x_center, y_center, cont_area) else: self.lbAuto.setText('Disabled.')
def videoFrame(self, image): self.cv_image = self.cv.imgmsg_to_cv2(image, "rgb8") self.cv_image = cv2.cvtColor(self.cv_image, cv2.COLOR_BGR2RGB) self.cv_image = cv2.resize(self.cv_image, (self.cv_image.shape[1]/2, self.cv_image.shape[0]/2)) lab_img, cont_image, center_mass, cont_area = find_car(self.cv_image, self.trackingColor, self.hsThreshold.value()/100.0) self.cv_image = find_rectangles(self.cv_image) qi = QImage(cont_image.data, cont_image.shape[1], cont_image.shape[0], QImage.Format_RGB888).rgbSwapped() self.lbVideo.setFixedHeight(cont_image.shape[0]) self.lbVideo.setFixedWidth(cont_image.shape[1]) self.lbVideo.setPixmap(QPixmap.fromImage(qi)) x_center = center_mass[0] y_center = center_mass[1] self.handle(cont_area) if self.cbAuto.isChecked(): self.fly(x_center, y_center, cont_area) else: self.lbAuto.setText('Disabled.')
def videoFrame(self, image): # Convert ROS image to OpenCV image self.cv_image = np.asarray(self.cv.imgmsg_to_cv(image, "rgb8")) self.cv_image = cv2.resize(self.cv_image, (self.cv_image.shape[1]/2, self.cv_image.shape[0]/2)) # Crop cv_image self.cv_image_cropped = self.cv_image # Blob detection algorithm lab_img, cont_image, center_mass, cont_area = find_car(self.cv_image_cropped , self.trackingColor, self.thresholdValue) #lab_img, cont_image, center_mass, cont_area = find_car(self.cv_image_cropped , self.trackingColor, self.hsThreshold.value()/100.0) # Create QImage for GUI video frame #qi_1 = QImage(cont_image.data, cont_image.shape[1], cont_image.shape[0], QImage.Format_RGB888) # Set GUI video feed parameters #self.lbVideo.setFixedHeight(cont_image.shape[0]) #self.lbVideo.setFixedWidth(cont_image.shape[1]) #self.lbVideo.setPixmap(QPixmap.fromImage(qi_1)) # Asign the center coordinates of the tracked blob self.x_center = center_mass[0] self.y_center = center_mass[1] # Recalculates the center of the blob self.updateCenterPositions(str(self.x_center),str(self.y_center)) # Scan QR codes from left to right if self.scanBlocksLeft2Right == True: self.lbAuto.setText('Aligning with blocks.') self.blocksDetected = self.blocks_detected2(99,self.cv_image,150,50) if self.blocksDetected == True: print "Blocks detected" self.scanBlocksLeft2Right = False self.alignPub.publish(True) self.blocksDetected = False # Scan QR codes from right to left elif self.scanBlocksRight2Left == True: self.lbAuto.setText('Aligning with blocks.') self.blocksDetected = self.blocks_detected2(210,self.cv_image,150,50) if self.blocksDetected == True: print "Blocks detected" self.scanBlocksRight2Left = False self.alignPub.publish(True) self.blocksDetected = False # Scan rail carts when command is sent from autonomy node elif self.scanAllCarts == True: self.lbAuto.setText('Scanning rail carts.') self.scanRailCarts(self.state) # Align with rail cart elif self.alignWithCartR2L == True: self.lbAuto.setText('Aligning with rail cart.') self.thresholdValue = 0.05 self.alignWithCartRight2Left() elif self.alignWithCartL2R == True: self.lbAuto.setText('Aligning with rail cart.') self.thresholdValue = 0.05 self.alignWithCartLeft2Right() # Scan individual cart color elif self.scanOneCart == True: self.lbAuto.setText('Scanning cart.') self.thresholdValue = 0.1 colorVal = 0 # Choose pixel in frame colorVal = self.calculateColor(self.cv_image[self.y, self.x]) self.test.publish(colorVal) self.scanOneCart = False