|
- """
- 版本更新:
- v12: 截取函数变化
- v13: 修正【截取中心区域】的算法的bug
- v15: 优化matplotlib对应的图片显示
- v16: 增加使用对应的脚本
- v17: 保存结果图
- v18: 让matplotlib灰度图显示正常
- v19:解决pycharm运行matplotlib报错
- v20:增加图片的BGR还是RGB显示
- """
-
- """
- 使用对应的脚本:
-
- import numpy as np
- import cv2
- import matplotlib.pyplot as plt
- import sys
- import copy
-
- sys.path.append("../..")
- from lib.fry_cv_utils_230425_v18 import FryCvUtils
-
- imgPath = r"../imgs/221009:压缩后.png"
- img = cv2.imread(imgPath)
- img_gray = cv2.cvtColor(img, cv2.COLOR_BGRA2GRAY)
-
- img_list=[img]
- FryCvUtils.plt_show_img(img_list,1,[2,2])
-
- FryCvUtils.printNumpyInfo("np11",np11)
- FryCvUtils.printNumpyInfo("canvas",canvas)
-
- """
-
- import numpy as np
- import cv2
- import matplotlib.pyplot as plt
- import math
- import copy
- import os
- from IPython.core.pylabtools import figsize # import figsize
-
- from PIL import Image, ImageDraw, ImageFont
- import matplotlib
- import matplotlib as mpl
-
- # 230425:解决pycharm运行matplotlib报错
- # mpl.use('TkAgg') # !IMPORTANT
- # mpl.use('AGG') # !IMPORTANT
- # mpl.use('AGG')
- mpl.use('qtagg')
-
- class FryCvUtils():
-
- @staticmethod
- def get_return_obj():
- """
- 作用:
- 返回对象的一般格式
- Returns:
- return_obj:返回的对象
- """
-
- return_obj={}
- return_obj['code']=200
- return_obj['success']=True
- return_obj['info_list']=[]
-
- """
- # return_obj['info_list'].append('尾部偏移太大,超过12px!')
- """
- # ! data里面就装各种返回来的数据,可以是各种格式
-
- return_obj['data']=None
-
- # ! 返回自定义的数据可以用对应的变量名
- line_list=None
- return_obj['line_list']=line_list
-
-
- return return_obj
-
- @staticmethod
- def printNumpyInfo(arrName,numpyArr):
- """
- 打印numpy变量的数据信息,这个在很多场合都非常有用
- :param arrName: 数组的名字
- :param numpyArr: numpy对应的那个数组
- :return:
- """
- print(arrName+" 数据类型:", type(numpyArr)) # 打印数组数据类型
- print(arrName+" 数组元素数据类型:", numpyArr.dtype) # 打印数组元素数据类型
- print(arrName+" 数组元素总数:", numpyArr.size) # 打印数组尺寸,即数组元素总数
- print(arrName+" 数组形状:", numpyArr.shape) # 打印数组形状
- print(arrName+" 数组的维度数目:", numpyArr.ndim) # 打印数组的维度数目
-
- @staticmethod
- def writeInImage(img, text='请输入文字', left=20, top=20, textColor=(0, 255, 0), textSize=20):
- # 判断是否为opencv图片类型
- if (isinstance(img, np.ndarray)):
- img = Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
- draw = ImageDraw.Draw(img)
- fontText = ImageFont.truetype('simsun.ttc', textSize, encoding="utf-8")
- draw.text((left, top), text, textColor, font=fontText)
-
- return cv2.cvtColor(np.asarray(img), cv2.COLOR_RGB2BGR)
-
- # image = cv2.imread('1.png')
- # # cv2.rectangle(image, (x_min, y_min), (x_max, y_max), (0, 0, 0), 2)
- # image = cv2ImgAddText(image, "中文", 40, 50, (0, 0, 0), 40)
-
- # #保存图片
- # cv2.imwrite("draw_text.jpg",image)
-
- return img1
-
-
- @staticmethod
- def cv_show(name,img):
- """
- 作用:
- 用于CV显示图片
- Args:
- name:显示图片的名字
- img:要显示的图片内容
- Returns:
- None
- """
- cv2.imshow(name, img)
- cv2.waitKey(0)
- cv2.destroyAllWindows()
-
-
- @staticmethod
- def plt_show_img(img_list,row_num=4,fig_size=(2,2),title="",saveImgPath="",imgType="BGR"):
- """
- 作用:
- 用matplotlib直接打印四张图片
- Args:
- img_list:被imshow的图片内容,是一个列表
- row_num:每行显示的图片数量,默认是4
- fig_size:
- # 设置 figsize,
- # 默认的像素:[6.0,4.0],分辨率为100,图片尺寸为 600&400
- # 指定dpi=200,图片尺寸为 1200*800
- # 指定dpi=300,图片尺寸为 1800*1200
- # 设置figsize可以在不改变分辨率情况下改变比例
- Returns:
- None
- """
-
- # 设置matplotlib库字体的非衬线字体为黑体
- plt.rcParams["font.sans-serif"] = ["SimHei"]
- # 设置matplotlib库字体族为非衬线字体
- plt.rcParams["font.family"] = "sans-serif"
-
- plt.rcParams['savefig.dpi'] = 300 # 图片像素
- plt.rcParams['figure.dpi'] = 300 # 分辨率
-
- textFont = {
- 'color': 'blueviolet',
- 'size': fig_size[0] * 3,
- }
-
- # plt.title(title, fontsize=fig_size[0]*3)
- # plt.text(0, 0, r' ' + title, fontdict={'size': fig_size[0]*3, 'color': 'blueviolet'})
-
- figsize(fig_size[0], fig_size[1]) # 设置 figsize
-
- # 第一步:把图片从BGR转换成RGB模式
- new_img_list = []
- imgCount = 0
- for imgI in img_list:
- assert (type(imgI) is np.ndarray), "图片只能是numpy类型"
- assert (imgI.ndim > 1), "图片必须是2维及以上"
- ansImgI = imgI
- # print("imgI.ndim :{}".format(imgI.ndim))
- if imgI.ndim == 1:
- ansImgI = imgI
- if imgI.ndim == 2:
- ansImgI = imgI
- if imgI.ndim == 3:
- # img_rgb2 = i[:,:,::-1]
- # 230324:opencv 报错‘depth‘ is 6 (CV_64F)全因numpy 默认float类型是float64位
- # 转成32的float就好
- ansImgI = imgI
- if ansImgI.dtype == "float64":
- ansImgI = ansImgI.astype("float32")
- # 230425:
- # 如果图片是BGR,默认转换了一道,所以我读BGR的图片是正常显示,而读RGB的图片就是异常显示了
- if "BGR" == imgType:
- ansImgI = cv2.cvtColor(ansImgI, cv2.COLOR_BGR2RGB)
- if imgI.ndim == 4:
- print("第 {} 张图片是4个通道".format(imgCount))
- new_img_list.append(ansImgI)
- imgCount += 1
-
- img_list = new_img_list
-
- num = len(img_list) # 总的显示图片的数量
- # 总行数
- rows = math.ceil(num/row_num)
- # 每行的元素个数
- per_row_num = []
- num1 = num
- while num1 > row_num:
- num1 = num1-row_num
- per_row_num.append(row_num)
- if(num1 > 0):
- per_row_num.append(num1)
- # print(per_row_num)
-
- fig, ax = plt.subplots()
-
- len1 = len(per_row_num)
- k = 0
- for i in range(1, len1+1):
- row_num2 = per_row_num[i-1]
- for j in range(1, row_num2+1):
- # print(len1,row_num,k+1)
- ax = plt.subplot(len1, row_num, k+1)
-
- # 如果有title才写title
- if len(title):
- textStr = r' ' + title+"_"+str(k)
- plt.text(-0.1, -0.4, r' ' + title+"_"+str(k), fontdict=textFont)
-
- # 如果是uint8,并且是3个通道
- if img_list[k].dtype == 'uint8' and img_list[k].ndim == 3:
- plt.imshow(img_list[k])
- else:
- plt.imshow(img_list[k], cmap='gray')
- # 如果是double类型或者是浮点类型
- k += 1
-
- # 230328:保存图片
- if len(saveImgPath):
- plt.savefig(saveImgPath)
-
- plt.show()
-
- @staticmethod
- def plt_show_img_gray(img_list,row_num=4,fig_size=(12,12)):
- """
- 作用:
- 先把灰度图转换为RGB图
- 方便用matplotlib显示图片的时候,效果比较好
- 用matplotlib直接打印四张图片
- Args:
- img_list:被imshow的图片内容,是一个列表
- row_num:每行显示的图片数量,默认是4
- Returns:
- None
- """
- # 第一步:把图片从灰度图转换成RGB模式
- new_img_list=[]
- for i in img_list:
- name1=cv2.cvtColor(i,cv2.COLOR_GRAY2RGB)
- new_img_list.append(name1)
-
- # 第二步:显示图片
- FryCvUtils.plt_show_img(new_img_list,row_num,fig_size)
-
-
-
-
- @staticmethod
- def list_dirFile(file_dir,postfix='csv',recursion=True):
- """
- 作用:
- 递归获取目录下指定后缀的文件名,
- 并将其存入到list中
- Args:
- file_dir: 目录地址
- postfix: 文件后缀,比如png,比如csv
- recursion: 是否递归
- Returns:
- ans_list: 指定后缀文件对应的列表
- """
-
- debug_model=False
-
- ans_list=[]
-
- postfix_add = '.'+postfix
-
- dir_list = os.listdir(file_dir)
- for cur_file in dir_list:
- path = os.path.join(file_dir,cur_file)
- #判断是文件夹还是文件
- if os.path.isfile(path):
- if debug_model:
- print("{0} : is file!".format(cur_file))
- dir_files = os.path.join(file_dir, cur_file)
- #判断是否存在.csv文件,如果存在则获取路径信息写入到ans_list列表中
- if debug_model:
-
- print(os.path.splitext(path)[1] == postfix_add)
- print(os.path.splitext(path)[1])
- print(postfix_add)
-
- if os.path.splitext(path)[1] == postfix_add:
-
- csv_file = os.path.join(file_dir, cur_file)
- if debug_model:
- print(os.path.join(file_dir, cur_file))
- print(csv_file)
- ans_list.append(csv_file)
- if os.path.isdir(path):
- if debug_model:
- print("{0} : is dir".format(cur_file))
- print(os.path.join(file_dir, cur_file))
- # 如果递归的话,就递归目录
- ans_list_children=[]
- if recursion:
- ans_list_children=FryCvUtils.list_dirFile(path,postfix,recursion)
- # 合并递归结果和自身结果
- ans_list= ans_list + ans_list_children
-
- if debug_model:
- print(ans_list)
- return ans_list
-
-
-
- @staticmethod
- def draw_line(canvas,x1=0,y1=0,x2=100,y2=100):
- """
- 作用:
- 在画布上划线
- Args:
- canvas:画布,就是要划线的图像
- x1:起点x
- y1:起点y
- x2:终点x
- y2:终点y
- Returns:
- canvas:画布,也就是被划线的那个图像
- """
- x1,y1,x2,y2=int(x1),int(y1),int(x2),int(y2)
- begin=(x1,y1)
- end=(x2,y2)
- point_color = (0, 0, 255) # BGR
- thickness = 1
- lineType = 8
- cv2.line(canvas, begin, end, point_color, thickness, lineType)
- return canvas
-
-
- @staticmethod
- def draw_many_lines(canvas,pos_list):
- """
- 作用:
- 在画布上划多条线
- Args:
- canvas:画布,就是要划线的图像
- 比如划两条线对应的数据为
- [(x1_1,y1_1,x2_1,y2_1),
- (x1_2,y1_2,x2_2,y2_2)
- ]
- pos_list:每条线的起始终止坐标对应的列表
- Returns:
- canvas:画布,也就是被划线的那个图像
- """
- for i in pos_list:
- canvas=FryCvUtils.draw_line(canvas,i[0],i[1],i[2],i[3])
- return canvas
-
- @staticmethod
- def cut_image(image,x,y,w,h):
- """
- 作用:
- 裁剪图片
- Args:
- image:被裁剪的图片
- x:起点的横坐标,也就是【宽】的那条线
- y:起点的纵坐标,也就是【高】的那条线
- w:裁剪的宽度
- h:裁剪的高度
- Returns:
- cut_image:被裁剪的图片
- """
- # ! 这里注意
- # ! 第0维是y,
- # ! 第一维才是x
- cut_image=image[y:y+h,x:x+w]
- return cut_image
-
- @staticmethod
- def judge_NonZero_rate(image,x,y,w,h):
- """
- 作用:
- 判断线中白色点的比例
- Args:
- Returns:
- nonZero_rate:非0的比例
- now_split_img:当前裁剪的图像
- """
- now_split_img=FryCvUtils.cut_image(image,x,y,w,h)
-
- total_count=now_split_img.size
- count = cv2.countNonZero(now_split_img)
- # ! 这个是为非0的比例,也就是检测正确的得分
- # ! 为0的比例就是100减去这个即可
- nonZero_rate=round(count/total_count,2)*100
- nonZero_rate=int(nonZero_rate)
- return nonZero_rate,now_split_img
-
- @staticmethod
- def judge_BinImg_row_no0_rate(binImage):
- """
- 作用:
- 判断二值图每一行非0的比例
- Args:
- Returns:
- 使用样例:
- 计算图片每一行非零比例
- row_no0_rate_list=FryCvUtils.judge_BinImg_row_no0_rate(th2)
- print(len(row_no0_rate_list))
- print(row_no0_rate_list)
- """
- debug_model=False
-
- img_h=img_row=binImage.shape[0]
- img_w=img_col=binImage.shape[1]
-
- list_no0_rate=[]
- for i in range(img_h):
- x=0
- y=i
- w=img_w
- h=1
-
- ans_rate,now_split_img=FryCvUtils.judge_NonZero_rate(binImage,x,y,w,h)
- if debug_model:
- print(x,y,w,h)
- print(now_split_img)
- print(ans_rate)
- list_no0_rate.append(ans_rate)
-
- return list_no0_rate
-
-
- @staticmethod
- def judge_BinImg_col_no0_rate(binImage):
- """
- 作用:
- 判断二值图每一列非0的比例
- Args:
- Returns:
- 使用样例:
- 找到每一列非0的比例
- col_no0_rate_list=FryCvUtils.judge_BinImg_col_no0_rate(th2)
- print(len(col_no0_rate_list))
- print(col_no0_rate_list)
- """
- debug_model=False
-
- img_h=img_row=binImage.shape[0]
- img_w=img_col=binImage.shape[1]
-
- list_no0_rate=[]
- for i in range(img_w):
- x=i
- y=0
- w=1
- h=img_h
- ans_rate,now_split_img=FryCvUtils.judge_NonZero_rate(binImage,x,y,w,h)
- if debug_model:
- print(x,y,w,h)
- print(now_split_img)
- print(ans_rate)
- list_no0_rate.append(ans_rate)
-
- return list_no0_rate
-
-
-
- @staticmethod
- def calc_meanVal_Pos(no_0_rate_list,offset=0):
- """
- 作用:
- 1、是为了获取核心区域的行高和列高
- 2、在列表中,找到大于数均值的起始位置和终止位置
- 3、也就是相当于找到均值的起始位置和终止位置
- Args:
- no_0_rate_list
- 函数功能样例:
- 比如如下数组,就是找到17后的92的位置,
- 以及找到最后的81前的91的位置
- [0, 0, 0, 0, 0, 0, 17, 92, 92, 93,
- 94, 94, 95, 95, 96, 96, 97, 98, 98,
- 96, 95, 94, 93, 93, 93, 92, 92, 91,
- 81, 3, 0, 0, 0]
- Returns:
- (startPos,endPos)
- 起始位置和终止位置
- 使用样例:
- 找到行的起始位置和终止位置
- row_pos=FryCvUtils.calc_meanVal_Pos(row_no0_rate_list)
- print(row_pos)
- print(row_no0_rate_list[row_pos[0]:row_pos[1]])
- """
- debug_model=False
-
- # 非零元素的和
- no_0_sum=0
- # 非零元素的个数
- no_0_count=0
-
- len_no_0_rate_list=len(no_0_rate_list)
- for i in range(len_no_0_rate_list):
- now_val=no_0_rate_list[i]
- if now_val>0:
- no_0_sum+=now_val
- no_0_count+=1
- # 非零元素的均值
- meanVal=no_0_sum/no_0_count
-
- print("meanVal: ",meanVal)
- if debug_model:
- print("meanVal: ",meanVal)
-
- # 找到均值的起始位置和终止位置
- startPos=0
- endPos=len_no_0_rate_list
- for j in range(len_no_0_rate_list):
- now_val=no_0_rate_list[j]
- if now_val>=meanVal+offset:
- startPos=j
- break
-
- no_0_rate_list_reverse=no_0_rate_list[::-1]
- for k in range(len_no_0_rate_list):
- now_val=no_0_rate_list_reverse[k]
- if now_val>=meanVal+offset:
- endPos=len_no_0_rate_list-1-k
- break
-
- # ! 现在得到的值是头尾我都要
- # 实际截取的时候一般是留头不留尾
- # 所以尾要加1
- # 这样方便我们的截取操作
-
- if (endPos+1)<=(len_no_0_rate_list-1):
- endPos+=1
-
- return (startPos,endPos)
-
- @staticmethod
- def get_Baseboard_part(image_path,offset=(1,3),type11='meanBin',bin_offset=0,del_direction=(True,True,True,True)):
- """
- 作用:
- 获取图片的中心区域
- 比如D41的底板区域
- 比如天马粒子的中心区域
- Args:
- offset: (row_offset,col_offset)
- type: 二值化类型
- meanBin: 均值二值化
- THRESH_OTSU: 大津二值化
- bin_offset: 二值化偏差的阈值
- 使用正数为加,使用负数为减
- del_direction:
- (上,右,下,左)
- del_direction=(True,True,True,True)
- 四个方向全为true,表示四个方向都删除
- 使用样例:
-
- """
- debug_model=False
- img5=cv2.imread(image_path)
- img_gray5 = cv2.cvtColor(img5,cv2.COLOR_BGR2GRAY)
-
- # 图形宽高
- img_h=img_row=img_gray5.shape[0]
- img_w=img_col=img_gray5.shape[1]
-
-
- img_binary11 = None
- if type11 == "meanBin":
- img_mean=np.mean(img_gray5)
- if debug_model:
- print(img_mean)
- ret, img_binary11 = cv2.threshold(img_gray5,img_mean+bin_offset,255,cv2.THRESH_BINARY)
- elif type11 == "THRESH_OTSU":
- # Otsu's thresholding
- ret2,img_binary11 = cv2.threshold(img_gray5,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
-
- del_direction_top=del_direction[0]
- del_direction_right=del_direction[1]
- del_direction_down=del_direction[2]
- del_direction_left=del_direction[3]
-
- # print(del_direction_top,del_direction_right,
- # del_direction_down,del_direction_left)
-
-
- direction_row=(del_direction_top or del_direction_down)
- if direction_row:
- # 计算图片每一行非零比例
- row_no0_rate_list=FryCvUtils.judge_BinImg_row_no0_rate(img_binary11)
- # 找到行的起始位置和终止位置
- row_pos=FryCvUtils.calc_meanVal_Pos(row_no0_rate_list)
-
- # print('row_pos',row_pos)
-
-
-
- direction_col=(del_direction_left or del_direction_right)
- if direction_col:
- # 找到每一列非0的比例
- col_no0_rate_list=FryCvUtils.judge_BinImg_col_no0_rate(img_binary11)
- # 找到列的起始位置和终止位置
- col_pos=FryCvUtils.calc_meanVal_Pos(col_no0_rate_list)
-
-
- # print('col_pos',col_pos)
-
- # 截取中心的核心区域
- row_offset=offset[0] # 传入参数中的y方向偏移
- col_offset=offset[1] # 传入参数中的x方向的偏移
-
- # 上
- top_pos=0
- if del_direction_top:
- top_pos = row_pos[0]+row_offset
-
- # 下
- down_pos=img_h
- if del_direction_down:
- down_pos=row_pos[1]-row_offset
-
- # 左
- left_pos=0
- if del_direction_left:
- left_pos=col_pos[0]+col_offset
-
- # 右
- right_pos=img_w
- if del_direction_right:
- right_pos=col_pos[1]-col_offset
-
- img_center = img_gray5[top_pos:down_pos,
- left_pos:right_pos]
- return img_center
-
-
- @staticmethod
- def get_Baseboard_part_batch(source_dir,dst_dir,postfix='bmp',offset=(1,3),type11='THRESH_OTSU',bin_offset=0,del_direction=(True,True,True,True),recursion=False):
- """
- 作用:
- 批量获取图片的中心区域
- Args:
- postfix: 文件的后缀
- offset: (row_offset,col_offset)
- type: 二值化类型
- meanBin: 均值二值化
- THRESH_OTSU: 大津二值化
- recursion: 是否递归文件夹
- 使用样例:
- """
- # 获取对应的文件名
- file_name_list=FryCvUtils.list_dirFile(source_dir,postfix,recursion)
-
- # 遍历每个图片,操作后保存
- save_path = dst_dir
- for i in range(len(file_name_list)):
- now_img_path = file_name_list[i]
- # print(now_img_path)
- now_img=cv2.imread(now_img_path)
- img_center=FryCvUtils.get_Baseboard_part(now_img_path,offset,type11,bin_offset,del_direction)
- os.makedirs(save_path,exist_ok=True)
- save_file_name= str(i)+'.'+postfix
- save_final_path=os.path.join(save_path , save_file_name)
- # print(save_final_path)
- cv2.imwrite(save_final_path,img_center)
-
-
-
- @staticmethod
- def sharpen(image):
- """
- 作用:
- 锐化
- 使用样例:
- img3=sharpen(img_median)
- """
- kernel = np.array([[0, -1, 0], [-1, 5, -1], [0, -1, 0]], np.float32) #锐化
- dst = cv2.filter2D(image, -1, kernel=kernel)
- return dst
-
-
- @staticmethod
- def cut_kernel_img(image,start_pos=(0,0),kernel_size=(3,3)):
- """
- 作用:
- 裁剪像卷积核一样的image
- Args:
- image:图像
- kernel_size:卷积核大小
- start_pos:起点坐标
- 说明:
- 最主要的是,裁剪的时候,照顾边缘的情况
- """
- img=image
-
- # 1、获取图像的宽高
- img_w = img.shape[1]
- img_h = img.shape[0]
-
- kernel_row=kernel_size[0]
- kernel_col=kernel_size[1]
-
- # ! 这里下面那个1写成了0
- start_pos_row=start_pos[0]
- start_pos_col=start_pos[1]
-
- row_start=start_pos_row-kernel_row//2
- row_end=row_start+kernel_row
- col_start=start_pos_col-kernel_col//2
- col_end=col_start+kernel_col
-
- if row_start<0:
- row_start=0
- row_end=row_start+kernel_row
-
- if col_start<0:
- col_start=0
- col_end=col_start+kernel_col
-
-
- # ! 不用减1,因为留头不留尾
- if row_end>img_h:
- row_end=img_h
- row_start=row_end-kernel_row
-
- if col_end>img_w:
- col_end=img_w
- col_start=col_end-kernel_col
-
-
- # print("========row_start,row_end,col_start,col_end========")
- # print(row_start,row_end,col_start,col_end)
-
- ans_img=img[row_start:row_end,col_start:col_end]
-
- return ans_img
-
- @staticmethod
- def draw_many_point(canvas,center_list,radius=1):
- """
- 作用:
- 在画布上画多个点
- Args:
- canvas:画布
- center_list:每个点对应的中心坐标
- [
- (x1,y1),
- (x2,y2)
- ]
- radius:半径
- Returns:
- canvas:画布,也就是被点的那个图像
- """
- new_canvas=copy.deepcopy(canvas)
- for i in range(len(center_list)):
- point_pos=center_list[i]
- cv2.circle(new_canvas, tuple(point_pos), radius, (0,255,0), -1)
-
- return new_canvas
-
-
- if __name__ == "__main__":
-
- img = np.random.randint(100,255,(320,320,3), np.uint8)
- img2 = np.random.randint(0,255,(320,320,3), np.uint8)
- # print(img.shape) # 输出:(320, 320, 3)
- # ! 测试显示图片
- # FryCvUtils.cv_show('img',img)
-
- # ! 测试plt显示图片
- # img_list=[img,img,img,img,img,img,img,img,img,img]
- # FryCvUtils.plt_show_img(img_list,2)
-
- # ! 测试显示灰度图
- # img_gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
- # img2_gray = cv2.cvtColor(img2,cv2.COLOR_BGR2GRAY)
- # img_list=[img_gray,img2_gray,img_gray,img2_gray,img_gray]
- # FryCvUtils.plt_show_img_gray(img_list,2)
-
- # ! 测试画线
- # img1_1=FryCvUtils.draw_line(img)
- # FryCvUtils.cv_show('img1_1',img1_1)
-
- # ! 测试画多条线
- # position_list=[(0,40,320,40),(0,140,320,140),(0,240,320,240)]
- # img1_1=FryCvUtils.draw_many_lines(img,position_list)
- # FryCvUtils.cv_show('img1_1',img1_1)
-
- # ! 测试裁剪图片
-
- # ! 测试在图片上写中文
- # img = np.random.randint(254,255,(320,320,3), np.uint8)
- # FryCvUtils.writeInImage(img, "中文", 40, 50, (0, 255, 0), 40)
- # # FryCvUtils.cv_show('img',img)
- # img_list=[img]
- # FryCvUtils.plt_show_img(img_list,1)
-
- # ! 测试获取指定目录下指定后缀的文件
- paths = r'D:/images/find_edge'
- ans_list=FryCvUtils.list_dirFile(paths,'png',False)
- print(ans_list)
-
-
-
-
-
|