两张图片的IOU"/>
计算两张图片的IOU
import cv2
import os
import numpy as np
from pathlib import Path
import time
from PIL import Image
import numpy as np#Read images
img1 = np.array(Image.open(032439.413.jpg"))#标注图
img2 = np.array(Image.open(32439.413.png"))#pytorch图片
#print(img1.shape)
#print(img2.shape)#convert unit8 to int numbers, then subtract, then 2D to 1D array
#subArr = np.subtract(img1[:, :, 0].tolist(), img2.tolist()).flatten()intersection = np.sum(np.logical_and(img1, img2[:, :, 0]))
union = np.sum(np.logical_or(img1, img2[:, :, 0]))#Intersection over Union
iou_score = intersection / unionprint(iou_score)
报错:
Img1 should be the .jpg file that has 3 channels
If your image is 2D, just delete one of the ,: from the code
Or just delete the [:,:,0]
If it's 2D, just img1, if it's 3D img1[:, :, 0]
更多推荐
计算两张图片的IOU
发布评论