def loadTrayImage(self, image_fname, csv_fname): """Load the tray scan image and activate the camera. Keyword Arguments: image_fname -- the string filepath of the tray scan image""" # Export current csv if there is one ret = self.exportToCSV() if not ret: return # Clear data self.reset() self.cvImpl.reset() self.barcodeEntry.setCurrentBugId("") # Load the image self.trayPath = image_fname self.logger.log("LOAD image scan file %s" % self.trayPath, 1) self.trayImage = cv2.imread(self.trayPath, cv2.IMREAD_COLOR) self.csvPath = csv_fname # Load csv file if os.path.isfile(csv_fname): with open(csv_fname) as csvfile: reader = csv.reader(csvfile) self.bugBoxList = Util.BugBoxList() if (reader.next()[1] == " Rectangle x1"): for b in reader: box = Util.BugBox( b[0], None, (int(b[1]), int(b[2]), int(b[3]), int(b[4])), (int(b[5]), int(b[6]))) self.bugBoxList.newBox(box) self.window.statusBar().showMessage( "Also loaded CSV file: %s" % str(os.path.split(csv_fname)[1])) self.logger.log( "LOAD found corresponding csv file %s" % self.csvPath, 1) else: QtGui.QMessageBox.information( self.window, "Error Reading CSV", "It seems the file %s id badly formatted. Cannot load." % str(os.path.split(csv_fname)[1])) # Start the camera loop self.startCameraFeed() self.sigShowHint.emit(C.HINT_TRAYAREA_1) self.bugBoxList.clearUndoRedoStacks()
def reset(self): """Reset internal attributes""" # Mouse position (current and last) on the big label self.mousePos = (0, 0) self.lastMousePos = (0, 0) # Variables used in keeping track of the placed boxes self.bugBoxList = Util.BugBoxList() self.removedBug = -1 # Variables used for editing the boxes self.selectedEditBox = None self.editAction = AppData.NO_ACTION # Show Hint self.sigShowHint.emit(C.HINT_LOADFILE) self.logger.log("RESET AppData", 0)