日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

二值mask图像 + RGB原图 生成可视化分割结果; 从二值mask获取分割轮廓点

發(fā)布時(shí)間:2025/3/19 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 二值mask图像 + RGB原图 生成可视化分割结果; 从二值mask获取分割轮廓点 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

?可視化分割結(jié)果:

import cv2 import numpy as np from tqdm import tqdm from PIL import Image from pathlib import Pathimage_root = Path('data/leftImg8bit/test/qdu') mask_root = Path('evaluation_logs/origin') save_root = Path('evaluation_logs/visual')for mask in tqdm(mask_root.iterdir()):name = mask.nameimagepath = image_root / name# mask = Image.open(mask)# image = Image.open(imagepath)# print(mask.mode) # L# print(image.mode) # RGBmask = cv2.imread(str(mask), cv2.IMREAD_GRAYSCALE)image = cv2.imread(str(imagepath), cv2.IMREAD_COLOR)# print(mask.shape) # 1080 1920# print(image.shape) # 1080 1920 3image = image.astype(np.float64)image[mask > 100] = (image[mask > 100] * 0.6).astype(np.int64)image[mask > 100] += np.array([100,0,0], dtype=np.int64)sp = save_root / namecv2.imwrite(str(sp), image)

從二值mask獲取分割輪廓點(diǎn):cv2.findcontours()

import cv2 from tqdm import tqdm from pathlib import Pathmask_root = Path('evaluation_logs/origin') image_root = Path('data/leftImg8bit/test/qdu')for maskpath in tqdm(mask_root.iterdir()):name = maskpath.namemask = cv2.imread(str(maskpath), cv2.IMREAD_GRAYSCALE)print(mask.shape) # 1080 1920contours, hierarchy = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)print(maskpath)# print(type(contours), len(contours))# print(type(contours[0]), contours[0].shape)# print(type(contours[1]), contours[1].shape)# print(type(hierarchy), hierarchy)outlines = []for cnt in contours:# print(type(cnt), cnt.shape)cnt = cnt[::,0,:]# print(type(cnt), cnt.shape)# print(cnt)cnt = cnt.tolist()# print(cnt)outlines.append(cnt)imagepath = image_root / nameimage = cv2.imread(str(imagepath), cv2.IMREAD_COLOR)for otl in outlines:for point in otl:cv2.circle(image, point, 1, (255,0,0))cv2.imshow('', image)cv2.waitKey(0)break

參考:python-opencv2利用cv2.findContours()函數(shù)來(lái)查找檢測(cè)物體的輪廓_hjxu2016的博客-CSDN博客_cv2.findcontours

總結(jié)

以上是生活随笔為你收集整理的二值mask图像 + RGB原图 生成可视化分割结果; 从二值mask获取分割轮廓点的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。