我是靠谱客的博主 心灵美眼睛,这篇文章主要介绍掩码图片转json 坐标数组, mask 转 json,现在分享给大家,希望可以做个参考。

主要方法为:findContours

不懂的自行百度吧, 自行修改代码生成json文件
# 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内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(135)

评论列表共有 0 条评论

立即
投稿
返回
顶部