def run(self): self.processRateCB.emit(0) if (self.pipeline is not None): length = len(self.pipeline) i = 1 params = self.params start_time = time.time() for node in self.pipeline: data = self.img_list[-1] try: ret_img = self.run_node(node, data) except Exception as e: print("ISP算法[{}]运行错误: {}".format(node, e)) return if(ret_img is not None): self.mutex.acquire() self.img_list.append(ret_img) self.mutex.release() else: critical(params.get_error_str()) break self.processRateCB.emit(i / length * 100) i += 1 stop_time = time.time() self.costTimeCB.emit('总耗时:{:.3f}s'.format(stop_time-start_time)) self.doneCB.emit() else: self.processRateCB.emit(100)
def update_awb_from_raw(self, viewportRect, fromScenePoint, toScenePoint): """ func: 鼠标选中事件的回调:执行AWB的选择区域或者图像分析的选择区域 """ if (toScenePoint.x() == 0 and toScenePoint.y() == 0 and self.rect[2] > self.rect[0] and self.rect[3] > self.rect[1]): if (self.select_awb == True): self.imageview.setDragMode(QGraphicsView.ScrollHandDrag) self.select_awb = False awb_ratio = self.img.get_raw_img_rect(self.rect) if (awb_ratio is not None): self.img_params.set_awb_ratio(awb_ratio) awb_gain = self.img_params.get_awb_gain() self.ui.awb_r.setValue(awb_gain[0]) self.ui.awb_g.setValue(awb_gain[1]) self.ui.awb_b.setValue(awb_gain[2]) else: critical("请在raw图上进行选择") else: if (self.histView is not None): self.histView.update_rect_data(self.show_img, self.rect) else: self.rect = [ int(fromScenePoint.x()), int(fromScenePoint.y()), int(toScenePoint.x()), int(toScenePoint.y()) ]
def set_watermark_img(self, filename): self.watermark_img = cv2.imdecode( np.fromfile(filename, dtype=np.uint8), -1) if (self.watermark_img is not None): self.watermark_img_height = self.watermark_img.shape[0] self.watermark_img_width = self.watermark_img.shape[1] else: critical('水印图片无法打开')
def open_watermark_path(self): watermarkpath = QFileDialog.getOpenFileName( None, '打开图片', './', "Images (*.jpg *.png *.bmp)") self.watermark_path = watermarkpath[0] if (self.watermark_path != ''): self.watermark_ui.watermark_path.setText(self.watermark_path) self.img.set_watermark_img(self.watermark_path) self.set_watermark_params() else: critical('打开水印图片失败')
def __init_img(self, filename): width = self.img_params.get_width() height = self.img_params.get_height() bit_depth = self.img_params.get_bit_depth() if (filename != "" and width != 0 and height != 0 and bit_depth != 0): if (self.img_pipeline.pipeline_reset() == True): self.img = self.img_pipeline.get_image(0) for i in range(1, self.ui.pipeline.count()): self.ui.pipeline.item(i).setCheckState(Qt.Unchecked) self.img.load_image(filename, height, width, bit_depth) self.img.set_bayer_pattern(self.img_params.get_pattern()) self.img_params.filename = filename self.rect = [0, 0, self.img_params.width, self.img_params.height] if (self.img.get_raw_data() is not None): self.displayImage(self.img) else: critical("打开图片失败,图片格式错误") else: critical("打开图片失败,图片格式错误")
def set_flatphoto(self): self.flatphoto = np.zeros( (self.rawformat.height, self.rawformat.width), dtype=np.float32) imagepath = QFileDialog.getOpenFileName(None, '打开平场图(RAW)', './', "raw (*.raw)") if imagepath[0] != '': try: flatphoto_ratio = np.fromfile(imagepath[0], dtype="uint16", sep="").reshape( (self.rawformat.height, self.rawformat.width)) except Exception: critical('打开图片错误') for blc, (y, x) in zip(self.blc.black_level, [(0, 0), (0, 1), (1, 0), (1, 1)]): tmp = cv2.medianBlur(flatphoto_ratio[y::2, x::2] - blc, 5) max_value = tmp.max() self.flatphoto[y::2, x::2] = max_value / tmp self.need_flush = True
def open_watermark_win(self): if(self.img.is_load_image == True): self.watermark_win = QDialog(self.imageview) self.watermark_ui = Ui_WaterMarkView() self.watermark_ui.setupUi(self.watermark_win) self.watermark_win.show() self.watermark_ui.open_watermark.clicked.connect( self.open_watermark_path) self.watermark_ui.change_transparent.valueChanged.connect( self.set_watermark_params) self.watermark_ui.change_watermark_size.valueChanged.connect( self.set_watermark_params) self.watermark_ui.change_watermark_th.valueChanged.connect( self.set_watermark_params) self.watermark_ui.change_watermark_type.currentIndexChanged.connect( self.set_watermark_params) self.watermark_ui.generate.clicked.connect(self.generate_watermark) self.watermark_ui.analysis.clicked.connect( self.analysis_space_watermark) else: critical('打开原图片失败,请先导入图片')
def displayImage(self, img): self.scene.clear() if img is not None: # numpy转qimage的标准流程 if len(img.shape) == 2: bytes_per_line = img.shape[1] qimg = QImage(img, img, img.shape[1], img.shape[0], QImage.Format_Grayscale8) elif img.shape[2] == 3: bytes_per_line = 3 * img.shape[1] qimg = QImage(img, img.shape[1], img.shape[0], bytes_per_line, QImage.Format_BGR888) elif img.shape[2] == 4: bytes_per_line = 4 * img.shape[1] qimg = QImage(img, img.shape[1], img.shape[0], bytes_per_line, QImage.Format_RGBA8888) else: critical("图片格式不能解析") self.scene.addPixmap(QPixmap.fromImage(qimg)) if(self.hist_window is not None and self.hist_window.enable is True): self.hist_window.update_rect_data( self.img.nowImage, self.rect)
def generate_code(self): self.params.get_params(self.ui) if os.path.exists(self.params.xmlfile) == False: return critical('需要转换的xml文件不存在') # 输出文件名的判断与处理 filename = self.params.output_path if (filename == ''): return critical('请填写转换后的头文件名称') filename_nosuffix = filename.split('/')[-1] if os.path.exists(filename): os.remove(filename) head_copyright = self.params.head_copyright.replace( "%AUTHOR%", self.params.author).replace( "%NOW_TINE%", time.strftime("%Y-%m-%d %H:%M", time.localtime())) head = head_copyright + "\n#ifndef _" + filename_nosuffix.upper().replace(".", "_") + \ "_\n#define _" + filename_nosuffix.upper().replace(".", "_") + "_\n\n" + self.params.include_headers + """ #ifdef __cplusplus #if __cplusplus extern "C" { #endif #endif """ + '\n' + self.params.add_custom_defines # 自定义结构体的替换 custom_define_dict_list = self.params.custom_define_dict.split("\n") custom_define_dict = {} for custom_define_dict_item in custom_define_dict_list: item = custom_define_dict_item.split(':') custom_define_dict[item[0]] = item[1] xmldata = xmldom.parse(self.params.xmlfile) data = xmldata.getElementsByTagName('SAVE_DATA') dataStruct = DataStruct(xmldata) total_process = len(data) if (len(self.params.filter_struct) == 0): self.params.filter_struct = dataStruct.mlist strGen = None output_text = [] output_text.append(head) now_process = 0 for node in data: name = node.getAttribute('PATH').split('.') value = node.getAttribute('VALUE') if (strGen is not None): if (name[0] != strGen.pri_name_0): tmp_text = strGen.finish(self.params.filter_struct) if (tmp_text != None): output_text.append(tmp_text) strGen = StructGen(name, dataStruct, self.params, custom_define_dict) strGen.add(name, value) else: strGen.add(name, value) else: strGen = StructGen(name, dataStruct, self.params, custom_define_dict) self.progress_bar.setValue(now_process / total_process * 100) now_process += 1 output_text.append(self.end) text = '\n\n'.join(output_text) self.ui.dst_file.setText(text) with open(filename, 'w') as f: f.write(text) self.progress_bar.setValue(100)
def error_report(self, value): """ func: 报告ISP算法错误 """ critical(value, self)