def fit(self, x, y, precision=0.007, step=0.04): h = precision prev_gammas = [0] * len(y) cur_gammas = [1] * len(y) cur_loo = self.__loo(x, y, h, cur_gammas) min_loo = cur_loo min_h = h while cur_loo > precision and h > step: h -= step print(h) idx = 0 while prev_gammas != cur_gammas: prev_gammas = cur_gammas for xi, yi in zip(x, y): newX = np.delete(x, xi) newY = np.delete(y, yi) parameter = self.__kern_smooth(xi, newX, newY, self._kernel, self._dist, h, cur_gammas) value = rectangle(abs(parameter - yi)) cur_gammas[idx] = value idx += 1 cur_loo = self.__loo(x, y, h, cur_gammas) if min_loo > cur_loo: min_loo = cur_loo min_h = h print("LOWESS MIN H", min_h) self._gammas = cur_gammas self._h = min_h self._x = x self._y = y
#剪切目录 imgcutpath = 'C:/Users/xiaoqiang/Desktop/NODE/public/zb_pythonF/table-detect-master/imgcut/' os.chdir(MyPath) for i in os.listdir(os.getcwd()): postfix = i #saveimg=i postfix = cv2.imread(postfix) print(type(postfix)) t = time.time() boxes, adBoxes, scores = table_detect(postfix, sc=(416, 416), thresh=0.5, NMSthresh=0.3) # print("正在处理" + i + "图片") # print("处理时间",time.time() - t, "边框坐标",boxes,"回归边框坐标",adBoxes,"置信度",scores) img = rectangle(postfix, adBoxes) #print(os.getcwd()) img.save(OutPath + i, "png") #cv2.imwrite(OutPath + i+ ".png", postfix) #print(MyPath + i) #saveimg = cv2.imread(MyPath + i) #print(type(saveimg)) img = cv2.imread(MyPath + i) # print(type(img)) for k in range(len(adBoxes)): # print("剪切第" + str(k) + "表格区域") # print(len(adBoxes)) crop1 = img[int(adBoxes[k][1]):int(adBoxes[k][3]), int(adBoxes[k][0]):int(adBoxes[k] [2])] # 裁剪坐标为[y0:y1, x0:x1] cv2.imwrite(imgcutpath + str(k) + i, crop1)
:param img: 源文件是cv2格式 :param adBoxes: bboxing的坐标列表,可以有多个 :return: """ img_name_split = img_name.split('.') img_name_prefix = '.'.join(img_name_split[:-1]) image_name_extention = '.' + img_name_split[-1] for idx, bbox in enumerate(adBoxes): xmin, ymin, xmax, ymax = [int(b) for b in bbox] crop_img = img[ymin:ymax,xmin:xmax] name = img_name_prefix + f'_cropimg_{idx}' + image_name_extention cv2.imwrite(name, crop_img) print(f'已经把表格保存到{name}') if __name__ == '__main__': import time # p = 'img/table-detect.jpg' p = 'img/table_without_line.jpg' #读取图片 img = cv2.imread(p) t = time.time() #获取bbox boxes, adBoxes, scores = table_detect(img, sc=(416, 416), thresh=0.5, NMSthresh=0.3) print(time.time() - t, boxes, adBoxes, scores) #把adBoxed画到图像上 newimg = rectangle(img, adBoxes) newimg.save('img/table_without_line_detect.png') # img.save('img/table_detect.png') #截取表格图像,并保存 crop_img(img_name=p, img=img, adBoxes=adBoxes)
def plot_rectangle(x,y, szx, szy, color, ax): utils.rectangle(x, y, szx, szy, color, ax)