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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

MaskRCNN路标:TensorFlow版本用于抠图

發(fā)布時(shí)間:2023/12/31 编程问答 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 MaskRCNN路标:TensorFlow版本用于抠图 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

??????????? MaskRCNN用于檢測(cè)路標(biāo),作為更詳細(xì)的目標(biāo)檢測(cè),用以得到更精準(zhǔn)的額路標(biāo)位置,路標(biāo)的幾何中心點(diǎn),用于構(gòu)建更為精準(zhǔn)的拓?fù)涞貓D,減少構(gòu)圖誤差。

??????????? 摳圖工具已經(jīng)完成,把框摳出來,用0值表示背景。


python代碼:

def mainex():#initDir();# Root directory of the projectROOT_DIR = os.getcwd()# Directory to save logs and trained modelMODEL_DIR = os.path.join(ROOT_DIR, "logs")# Path to trained weights file# Download this file and place in the root of your# project (See README file for details)#COCO_MODEL_PATH = os.path.join(ROOT_DIR, "mask_rcnn_coco.h5")COCO_MODEL_PATH= "D:/Works/PyProj/MaskRCNN-tensor/data/model/mask_rcnn_coco.h5";# Directory of images to run detection on#IMAGE_DIR = os.path.join(ROOT_DIR, "images");IMAGE_DIR = "data/MedSeaTest/";config = InferenceConfig()config.display();# 3.# Create model object in inference mode.model = modellib.MaskRCNN(mode="inference", model_dir=MODEL_DIR, config=config)# Load weights trained on MS-COCOmodel.load_weights(COCO_MODEL_PATH, by_name=True);# 4class_names= init_classname();IMAGE_DIR = "D:/DataSet/PicStyleTest/Medsea3/deskfilter/";proDir(model, class_names, IMAGE_DIR);
處理目錄:

def proDir( model,class_names,IMAGE_DIR ):# Load a random image from the images folderprint(IMAGE_DIR);extention =".jpg";filelist =traverseFolder( IMAGE_DIR , extention);#traverse( IMAGE_DIR , extention);#for file in filelist:print("Is processing: ");print(file);image = skimage.io.imread( file );# Run detectionresults = model.detect([image], verbose=1);# Visualize results#r = results[0];fileName = file;getAllLabelMask(fileName, image, results[0], class_names)
def getAllLabelMask(fileName,image, maskResult,class_names ):"""boxes: [num_instance, (y1, x1, y2, x2, class_id)] in image coordinates.masks: [num_instances, height, width]class_ids: [num_instances]class_names: list of class names of the datasetscores: (optional) confidence scores for each boxfigsize: (optional) the size of the image."""boxes = maskResult['rois'];masks = maskResult['masks']; scores = maskResult['scores'];class_ids = maskResult['class_ids'];# Number of instancesN = boxes.shape[0];if not( N<1 or boxes.shape[0] == masks.shape[-1] == class_ids.shape[0]):returnrow = image.shape[1];col = image.shape[0];for i in range(N):# Bounding boxif not np.any(boxes[i]): continue;y1, x1, y2, x2 = boxes[i];# Labelclass_id = class_ids[i];score = scores[i] if scores is not None else Nonelabel = class_names[class_id];# Maskmask = masks[:, :, i];masked_image = np.zeros((col, row, 3), dtype=np.uint8);masked_image = apply_maskX(masked_image, mask);#frontImage = np.zeros( (col, row), dtype=np.uint8 );frontImage = image.copy();for m in range(row):for n in range(col):if(masked_image[n, m, 0]<254):#frontImage[n, m] = 255;frontImage[n,m,0] =0;frontImage[n, m, 1] = 0;frontImage[n, m, 2] = 0;#roiMask = masked_image[y1:y2, x1:x2];roiImg = frontImage[y1:y2, x1:x2];roiImg = cv2.cvtColor(roiImg, cv2.COLOR_BGR2RGB);fileMask = fileName[0: len(fileName)-4];fileMask = fileMask +"."+ str(i)+"."+label+"."+"Mask.png";cv2.imwrite(fileMask, roiImg);

結(jié)果:








總結(jié)

以上是生活随笔為你收集整理的MaskRCNN路标:TensorFlow版本用于抠图的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

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