主要方法为:findContours
不懂的自行百度吧, 自行修改代码生成json文件
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39# encoding: utf-8 """ @author: _Jack Sparrow @time: 2022/7/28 16:35 @file: mask_as_json.py @desc: 掩码图片转json """ import cv2 import pandas as pd import os def get_coor(img): gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # 变为灰度图 #ret, binary = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU) ## 阈值分割得到二值化图片 # cv2.namedWindow('binary', cv2.WINDOW_AUTOSIZE) # cv2.imshow('binary', binary) # cv2.waitKey(0) contours, heriachy = cv2.findContours(gray, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) pointsList = [] print(len(contours)) # 目标个数 for i, contour in enumerate(contours): # print(heriachy) if len(contour) < 20: continue num = len(contour[:, 0, 0]) # 个数 hundred = num // 80 # 每个点之间的步长 tem = contour[:, 0][::hundred] return tem, 1 if __name__ == '__main__': img_path = r"c://......" img = cv2.imread(img_path) h, w = img.shape[:-1] contours, flag = get_coor(img) # 坐标数组contours
最后
以上就是心灵美眼睛最近收集整理的关于掩码图片转json 坐标数组, mask 转 json的全部内容,更多相关掩码图片转json内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复