# Convert Kitti labels to Yolo

Hi, Trying to convert Kitti label format to Yolo. But after converting the bbox is misplaced. this is kitti bounding box this is conversion code:

``````def convertToYoloBBox(bbox, size):
# Yolo uses bounding bbox coordinates and size relative to the image size.
# This is taken from https://pjreddie.com/media/files/voc_label.py .
dw = 1. / size
dh = 1. / size
x = (bbox + bbox) / 2.0
y = (bbox + bbox) / 2.0
w = bbox - bbox
h = bbox - bbox
x = x * dw
w = w * dw
y = y * dh
h = h * dh
return (x, y, w, h)

convert =convertToYoloBBox([kitti_bbox,kitti_bbox,kitti_bbox,kitti_bbox],image.shape[:2])
``````

The function does some normalization which is essential for yolo and outputs following:

(0.14763590391908976, 0.3397063758389261, 0.20452591656131477, 0.01810402684563757)

but when i try to check if the normalization is being done correctly with this code:

``````x = int(convert * image.shape)
y = int(convert * image.shape)
width = x+int(convert * image.shape)
height = y+ int(convert * image.shape)

cv.rectangle(image, (int(x), int(y)), (int(width), int(height)), (255,0,0), 2 )
``````

Bounding box is misplaced: Any suggestions ? Is conversion fucntion correct? or the problem is in the checking code ?

I reckon the problem is located when doing

``````x = int(convert * image.shape)
y = int(convert * image.shape)
``````

As `convert` contains the x position but centered. Same happens with `convert`. This center position introduces the offset in the bbox you drawed.

UPDATE
Based on your code, replace as follows

``````x = int((convert - convert/2))*im.size
y = int((convert - convert/2))*im.size
width = int(convert*im.size)
height = int(convert*im.size)

cv.rectangle(image, (int(x), int(y)), (int(width), int(height)), (255,0,0), 2 )`````````