'Distance calculation between objects in MS COCO dataset
I have dataset includes images and its JSON file (MS COCO format) and only single class problem, I need to Calculate the distances between objects and find the center for each object in MS coco dataset and Group the images based on number of objects and distances in each image.
The segmentation or annotation of this dataset is tooth, which means segmenting each tooth separately. After calculating the distances, we can group the images(some images have 32 teeth, while others have something between maybe 20-28.
Here's dataset https://drive.google.com/file/d/13xpt7ppnQ56OUORq6TOjJOWGWskkoj5R/view?usp=sharing
Here are images https://drive.google.com/drive/folders/1G7Yc5ttUMqDFpPsZLb2s-4i5MVh5jkIl?usp=sharing
Here's my code:
from pycocotools.coco import COCO
import numpy as np
import skimage.io as io
import random
import os
import cv2
from tensorflow.keras.preprocessing.image import ImageDataGenerator
### For visualizing the outputs ###
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
dataDir='./COCOdataset2017'
dataType='val'
annFile='{}/annotations/instances_{}.json'.format(dataDir,dataType)
# Initialize the COCO api for instance annotations
coco=COCO(annFile)
# Load the categories in a variable
catIDs = coco.getCatIds()
cats = coco.loadCats(catIDs)
print(cats)
def getClassName(classID, cats):
for i in range(len(cats)):
if cats[i]['id']==classID:
return cats[i]['name']
return "None"
print('The class name is', getClassName(77, cats))
#####################################################################
filterClasses = ['tooth']
# Fetch class IDs only corresponding to the filterClasses
catIds = coco.getCatIds(catNms=filterClasses)
# Get all images containing the above Category IDs
imgIds = coco.getImgIds(catIds=catIds)
print("Number of images containing all the classes:", len(imgIds))
annIds = coco.getAnnIds(imgIds=img['id'], catIds=catIds, iscrowd=None)
anns = coco.loadAnns(annIds)
coco.showAnns(anns)
####################
#### GENERATE A SEGMENTATION MASK ####
filterClasses = ['tooth']
mask = np.zeros((img['height'],img['width']))
for i in range(len(anns)):
className = getClassName(anns[i]['category_id'], cats)
pixel_value = filterClasses.index(className)+1
mask = np.maximum(coco.annToMask(anns[i])*pixel_value, mask)
plt.imshow(mask)
I don't know how to calculate distance between objects and calculating center of objects
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
