def calc_eba(self): edgePix = int(5000 / self.size) coor = coordinateForCv() if self.eject_edge_or_not.isChecked(): coor = coordinateForCv() coor.eba_calc(self.all_num_with_edge,self.all_cnt_with_edge,self.all_cnt_area_with_edge,self.imgray_mask,self.imgray) else: coor = coordinateForCv() coor.eba_calc(self.all_num,self.all_cnt,self.all_cnt_area,self.imgray_mask,self.imgray)
def calc_eba(self): edgePix = int(5000 / self.size) coor = coordinateForCv() if self.eject_edge_or_not.isChecked(): coor = coordinateForCv() coor.eba_calc(self.all_num_with_edge, self.all_cnt_with_edge, self.all_cnt_area_with_edge, self.imgray_mask, self.imgray) else: coor = coordinateForCv() coor.eba_calc(self.all_num, self.all_cnt, self.all_cnt_area, self.imgray_mask, self.imgray)
def all_drowcontour(self): self.init_var() count = pic_count() #self.imgray=cv2.bilateralFilter(self.imgray,10,20,5) imgray, im_color = count.gray_range_select(self.imgray, self.smallRange, self.largeRange) #imgray,im_color = count.gray_range_select(self.imgray,80,160) """ cv2.imshow("",imgray) cv2.waitKey(0) cv2.destroyAllWindows() """ self.imgray_mask, self.all_num, self.all_cnt, self.all_cnt_area = count.all_contour( imgray, self.maxArea, self.minArea) self.imgray_mask, self.all_cnt_area = self.check_edge() coor = coordinateForCv() self.cv_img = coor.cv2pyqtgraph(self.imgray_mask) imgray_mask_bool = np.asarray(self.cv_img, np.bool8) self.all_mask = np.zeros_like(self.pyqt_pic) self.all_mask[imgray_mask_bool] = (255, 255, 0) self.open_or_add_pic(self.pyqt_pic, self.all_mask, 0.7, 0.7) self.make_histogram() self.all_con = self.add
def cut_area(self): if self.cur_cnt is None: pass else: coo = coordinateForCv() top, bottom, left, right = coo.contour_data(self.cur_cnt) if top - 5 >= 0: top = top - 5 if bottom + 10 <= self.im.shape[0]: bottom = bottom + 10 if left - 5 >= 0: left = left - 5 if right + 10 <= self.im.shape[1]: right = right + 10 im_con = self.im[top:bottom, left:right, :] scale_pic = self.make_scale(im_con) filename = self.last_dir + '/' + 'contour.jpg' + '\'' temp_file = QtGui.QFileDialog.getSaveFileName( self, directory=filename, filter="Image Files (*jpg *.png *.bmp )") if temp_file == None: pass else: cv2.imwrite(temp_file[0], scale_pic)
def recover_area(self): self.erase_num.pop() cou = pic_count() erased_mask_cv,self.cur_contour_area = cou.re_draw_contour(self.im,self.all_num,self.all_cnt,self.all_cnt_area,self.erase_num) coor = coordinateForCv() erased_mask_qt = coor.cv2pyqtgraph(erased_mask_cv) self.open_or_add_pic(self.pyqt_pic,erased_mask_qt,0.7,0.7) self.all_con = self.add self.make_histogram()
def sub_window_pic(self,im): if self.sub_vb == None: self.sub_vb = self.sub_view.addViewBox() else: self.sub_vb.clear() self.sub_vb.setAspectLocked(True) self.sub_item = pg.ImageItem() self.sub_vb.addItem(self.sub_item) coor = coordinateForCv() self.pyqt_imgray = coor.cv2pyqtgraph(im) self.sub_item.setImage(self.pyqt_imgray)
def sub_window_pic(self, im): if self.sub_vb == None: self.sub_vb = self.sub_view.addViewBox() else: self.sub_vb.clear() self.sub_vb.setAspectLocked(True) self.sub_item = pg.ImageItem() self.sub_vb.addItem(self.sub_item) coor = coordinateForCv() self.pyqt_imgray = coor.cv2pyqtgraph(im) self.sub_item.setImage(self.pyqt_imgray)
def recover_area(self): self.erase_num.pop() cou = pic_count() erased_mask_cv, self.cur_contour_area = cou.re_draw_contour( self.im, self.all_num, self.all_cnt, self.all_cnt_area, self.erase_num) coor = coordinateForCv() erased_mask_qt = coor.cv2pyqtgraph(erased_mask_cv) self.open_or_add_pic(self.pyqt_pic, erased_mask_qt, 0.7, 0.7) self.all_con = self.add self.make_histogram()
def mouseMoved(self,pos): pyqt_pos = self.pic_item.mapFromScene(pos.pos()) item = self.pic_item.boundingRect() co = coordinateForCv() _w,_h = int(item.width()),int(item.height()) if pyqt_pos.x() < 0 or pyqt_pos.y() < 0 or pyqt_pos.x() > _w or pyqt_pos.y() > _h: pass else : pic_coordinate = co.coordinate2cv(int(pyqt_pos.x()),int(pyqt_pos.y()),_w,_h) x = np.ndarray.tolist(pic_coordinate[1]) y = np.ndarray.tolist(pic_coordinate[0]) self.curPos= (x[0]+2,y[0]+2)
def mouseMoved(self, pos): pyqt_pos = self.pic_item.mapFromScene(pos.pos()) item = self.pic_item.boundingRect() co = coordinateForCv() _w, _h = int(item.width()), int(item.height()) if pyqt_pos.x() < 0 or pyqt_pos.y() < 0 or pyqt_pos.x( ) > _w or pyqt_pos.y() > _h: pass else: pic_coordinate = co.coordinate2cv(int(pyqt_pos.x()), int(pyqt_pos.y()), _w, _h) x = np.ndarray.tolist(pic_coordinate[1]) y = np.ndarray.tolist(pic_coordinate[0]) self.curPos = (x[0] + 2, y[0] + 2)
def contour_select(self): if self.all_cnt is None : pass else: for i ,cnt in zip(self.all_num,self.all_cnt): in_out = cv2.pointPolygonTest(cnt,(self.curPos[0],self.curPos[1]),False) if in_out == 1 or in_out == 0: self.cur_contour = np.zeros_like(self.im) cv2.drawContours(self.cur_contour,[cnt],0,(0,255,0),-1) coor = coordinateForCv() self.cur_cnt = cnt self.cur_cnt_number = i self.cv_img = coor.cv2pyqtgraph(self.cur_contour) self.open_or_add_pic(self.pyqt_pic,self.cv_img,0.2,1) else : pass
def check_edge(self): if self.all_num == None: return else: count = pic_count() if self.eject_edge_or_not.isChecked(): self.all_num_with_edge=self.all_num self.all_cnt_with_edge=self.all_cnt self.all_area_with_edge = self.all_cnt self.imgray_mask_with_edge = self.imgray_mask coordinate = coordinateForCv() self.all_num,self.all_cnt,self.all_cnt_area,self.edge_num,self.edge_cnt,self.edge_area,self.edgeSum =coordinate.check_edge(self.im,self.all_num,self.all_cnt,self.all_cnt_area) erased_mask,cur_contour_area = count.mono_re_draw_contour(self.im,self.all_num,self.all_cnt,self.all_cnt_area,self.erase_num) return erased_mask,cur_contour_area else: erased_mask,cur_contour_area = count.mono_re_draw_contour(self.im,self.all_num,self.all_cnt,self.all_cnt_area,self.erase_num) return erased_mask,cur_contour_area
def contour_select(self): if self.all_cnt is None: pass else: for i, cnt in zip(self.all_num, self.all_cnt): in_out = cv2.pointPolygonTest(cnt, (self.curPos[0], self.curPos[1]), False) if in_out == 1 or in_out == 0: self.cur_contour = np.zeros_like(self.im) cv2.drawContours(self.cur_contour, [cnt], 0, (0, 255, 0), -1) coor = coordinateForCv() self.cur_cnt = cnt self.cur_cnt_number = i self.cv_img = coor.cv2pyqtgraph(self.cur_contour) self.open_or_add_pic(self.pyqt_pic, self.cv_img, 0.2, 1) else: pass
def cut_area(self): if self.cur_cnt is None: pass else: coo = coordinateForCv() top,bottom,left,right =coo.contour_data(self.cur_cnt) if top-5 >= 0 : top = top - 5 if bottom + 10 <= self.im.shape[0]: bottom = bottom +10 if left - 5 >= 0: left = left - 5 if right + 10 <= self.im.shape[1]: right = right + 10 im_con = self.im[top:bottom,left:right,:] scale_pic = self.make_scale(im_con) filename = self.last_dir + '/' + 'contour.jpg' + '\'' temp_file = QtGui.QFileDialog.getSaveFileName(self,directory = filename,filter="Image Files (*jpg *.png *.bmp )") if temp_file == None: pass else: cv2.imwrite(temp_file[0],scale_pic)
def all_drowcontour(self): self.init_var() count = pic_count() #self.imgray=cv2.bilateralFilter(self.imgray,10,20,5) imgray,im_color = count.gray_range_select(self.imgray,self.smallRange,self.largeRange) #imgray,im_color = count.gray_range_select(self.imgray,80,160) """ cv2.imshow("",imgray) cv2.waitKey(0) cv2.destroyAllWindows() """ self.imgray_mask,self.all_num,self.all_cnt,self.all_cnt_area = count.all_contour(imgray,self.maxArea,self.minArea) self.imgray_mask,self.all_cnt_area = self.check_edge() coor = coordinateForCv() self.cv_img = coor.cv2pyqtgraph(self.imgray_mask) imgray_mask_bool = np.asarray(self.cv_img,np.bool8) self.all_mask = np.zeros_like(self.pyqt_pic) self.all_mask[imgray_mask_bool]=(255,255,0) self.open_or_add_pic(self.pyqt_pic,self.all_mask,0.7,0.7) self.make_histogram() self.all_con = self.add
def check_edge(self): if self.all_num == None: return else: count = pic_count() if self.eject_edge_or_not.isChecked(): self.all_num_with_edge = self.all_num self.all_cnt_with_edge = self.all_cnt self.all_area_with_edge = self.all_cnt self.imgray_mask_with_edge = self.imgray_mask coordinate = coordinateForCv() self.all_num, self.all_cnt, self.all_cnt_area, self.edge_num, self.edge_cnt, self.edge_area, self.edgeSum = coordinate.check_edge( self.im, self.all_num, self.all_cnt, self.all_cnt_area) erased_mask, cur_contour_area = count.mono_re_draw_contour( self.im, self.all_num, self.all_cnt, self.all_cnt_area, self.erase_num) return erased_mask, cur_contour_area else: erased_mask, cur_contour_area = count.mono_re_draw_contour( self.im, self.all_num, self.all_cnt, self.all_cnt_area, self.erase_num) return erased_mask, cur_contour_area
def pic_set(self): if len(self.im.shape) == 3: color = self.setCurrentIndex() smooth = self.setsmooth() count = pic_count() blur = count.smoothing(self.im,smooth) self.imgray = count.color_filter(blur,color) self.sub_window_pic(blur) #cv2.imshow("",self.imgray) #cv2.waitKey(0) #cv2.destroyAllWindows() else: self.imgray = self.im coor = coordinateForCv() self.pyqt_pic = coor.cv2pyqtgraph(self.im) if self.vb == None: self.vb = self.pic_view.addViewBox(enableMenu=False) self.vb.setAspectLocked(True) #self.vb.setMouseEnabled(y=False) #self.vb.setMouseEnabled(x=False) else: pass self.open_or_add_pic(self.pyqt_pic)
def pic_set(self): if len(self.im.shape) == 3: color = self.setCurrentIndex() smooth = self.setsmooth() count = pic_count() blur = count.smoothing(self.im, smooth) self.imgray = count.color_filter(blur, color) self.sub_window_pic(blur) #cv2.imshow("",self.imgray) #cv2.waitKey(0) #cv2.destroyAllWindows() else: self.imgray = self.im coor = coordinateForCv() self.pyqt_pic = coor.cv2pyqtgraph(self.im) if self.vb == None: self.vb = self.pic_view.addViewBox(enableMenu=False) self.vb.setAspectLocked(True) #self.vb.setMouseEnabled(y=False) #self.vb.setMouseEnabled(x=False) else: pass self.open_or_add_pic(self.pyqt_pic)
def scrollbar_before(self): self.pic_view.scene().sigMouseClicked.connect(self.mouseMoved) coor = coordinateForCv() self.namelist, self.files_len, self.filename_pos = coor.get_list_and_index( self.filename[0]) self.scrollbar_set(self.files_len, self.filename_pos)
def make_canny(self): cv_test = opencv_test() cv_img = cv_test.canny(self.im) coor = coordinateForCv() self.canny = coor.cv2pyqtgraph(cv_img) self.open_or_add_pic(self.canny)
def scrollbar_before(self): self.pic_view.scene().sigMouseClicked.connect(self.mouseMoved) coor = coordinateForCv() self.namelist, self.files_len, self.filename_pos = coor.get_list_and_index(self.filename[0]) self.scrollbar_set( self.files_len, self.filename_pos)