def correctColor(self): if self.colorcardParams == None: if len(self.colorcardList) > 0: medianSize = cd.getMedianRectSize(self.colorcardList) capturedColorcards = cd.rectifyRectImages(self.image, self.colorcardList, medianSize) self.colorcardColors, _ = cd.getColorcardColors(capturedColorcards[0], GridSize = [6, 4]) self.colorcardParams = cd.estimateColorParameters(cd.CameraTrax_24ColorCard, self.colorcardColors) else: self.status.append('Need to select a color card first.') return colorMatrix, colorConstant, colorGamma = self.colorcardParams self.imageCorrected = cd.correctColorVectorised(self.image.astype(np.float), colorMatrix, colorConstant, colorGamma) self.imageCorrected[np.where(self.imageCorrected < 0)] = 0 self.imageCorrected[np.where(self.imageCorrected > 255)] = 255 self.imageCorrected = self.imageCorrected.astype(np.uint8) self.updateFigure(self.imageCorrected)
def savePipelineSettings(self): ''' save to pipeline setting file''' self.settingFileName = str(QtGui.QFileDialog.getSaveFileName(self, \ 'Save selection (default in ./_data)', self.timestreamRootPath)) if len(self.settingFileName) == 0: return self.settingPath = os.path.relpath(os.path.dirname(self.settingFileName), self.timestreamRootPath) self.settings = {} if self.ImageSize != None and self.CameraMatrix != None and self.DistCoefs != None: undistortDic = {'cameraMatrix': self.CameraMatrix.tolist(), \ 'distortCoefs': self.DistCoefs.tolist(), \ 'imageSize': list(self.ImageSize), 'rotationAngle': self.rotationAngle + self.smaleRotationAngle } else: undistortDic = {} self.settings['undistort'] = undistortDic if len(self.colorcardList) > 0: medianSize = cd.getMedianRectSize(self.colorcardList) capturedColorcards = cd.rectifyRectImages(self.image, self.colorcardList, medianSize) colorCardFile = 'CapturedColorcard.png' cv2.imwrite(os.path.join(self.timestreamRootPath, self.settingPath, colorCardFile), capturedColorcards[0][:,:,::-1].astype(np.uint8)) colorcardColors, colorStd = cd.getColorcardColors(capturedColorcards[0], GridSize = [6,4]) colorcardPosition, Width, Height, Angle = cd.getRectangleParamters(self.colorcardList[0]) colorcardDic = {'colorcardFile': colorCardFile,\ 'colorcardPosition': colorcardPosition.tolist(),\ 'colorcardTrueColors': cd.CameraTrax_24ColorCard,\ 'settingPath': '_data' } else: colorcardDic = {} self.settings['colorcarddetect'] = colorcardDic self.settings['colorcorrect'] = {'minIntensity': 15} if len(self.trayList) > 0: trayMedianSize = cd.getMedianRectSize(self.trayList) trayImages = cd.rectifyRectImages(self.image, self.trayList, trayMedianSize) trayDict = {} trayDict['settingPath'] = '_data' trayDict['trayNumber'] = len(self.trayList) trayDict['trayFiles'] = 'Tray_%02d.png' trayPositions = [] for i,tray in enumerate(trayImages): cv2.imwrite(os.path.join(self.timestreamRootPath, self.settingPath, trayDict['trayFiles'] %i), tray[:,:,::-1].astype(np.uint8)) trayPosition, Width, Height, Angle = cd.getRectangleParamters(self.trayList[i]) trayPositions.append(trayPosition.tolist()) trayDict['trayPositions'] = trayPositions else: trayDict = {} self.settings['traydetect'] = trayDict if len(self.potList) > 0: trayMedianSize = cd.getMedianRectSize(self.trayList) potPosition, Width, Height, Angle = cd.getRectangleParamters(self.potList[0]) Width, Height = int(Width), int(Height) topLeft = [int(self.potList[0][0][0]), int(self.potList[0][0][1])] self.potImage = self.image[topLeft[1]:topLeft[1]+Height, topLeft[0]:topLeft[0]+Width, :] potFile = 'Pot.png' cv2.imwrite(os.path.join(self.timestreamRootPath, self.settingPath, potFile), self.potImage[:,:,::-1].astype(np.uint8)) potDict = {} potDict['potPositions'] = potPosition.tolist() potDict['potSize'] = [int(Width), int(Height)] potDict['traySize'] = [int(trayMedianSize[0]), int(trayMedianSize[1])] potDict['potFile'] = potFile potDict['potTemplateFile'] = 'PotTemplate.png' potDict['settingPath'] = '_data' potTemplatePathIn = os.path.join(self.scriptPath, './data/PotTemplate.png') potTemplatePathOut = os.path.join(self.timestreamRootPath, self.settingPath, potDict['potTemplateFile']) shutil.copyfile(potTemplatePathIn, potTemplatePathOut) if self.potTemplate != None: potTemplateFile = 'potTemplate.png' cv2.imwrite(os.path.join(self.timestreamRootPath, self.settingPath, potTemplateFile), self.potTemplate[:,:,::-1]) potDict['potTemplateFile'] = potTemplateFile else: potDict = {} self.settings['potdetect'] = potDict self.settings['plantextract'] = {'meth': 'method1', 'methargs': {'threshold' : 0.6, 'kSize' : 5, 'blobMinSize' : 50} } with open(self.settingFileName, 'w') as outfile: outfile.write( yaml.dump(self.settings, default_flow_style=None) ) self.status.append('Saved initial data to ' + self.settingFileName)