1
$\begingroup$

I have a labeled dataset for object detection few thousands of images with annotation on csv file

the csv contains these columns image_path, class, xmax, xmin, ymax, ymin

looks like Pascal voc format labeles but when I plot it, it does't work and all labels look wrong

I noticed that there are some values in negtive in xmin, ymin and that's weird

so I'm asking which kind of labeling formats that has the possibility to have these kinds of values because it's ?

as example a bbox has these

xmax: 429 xmin: -68 ymax = 390 ymin = 130

the code I used is:

import cv2
import pandas as pd 
df = pd.read_csv('train.csv')

directory = 'dataset/images'

color = (255, 0, 0)
thickness = 2
org = (50, 50)
fontScale = 1
font = cv2.FONT_HERSHEY_SIMPLEX

for i in df.index:
  image_path = df.iloc[i]['image_path']
  xmax = int(df.iloc[i]['xmax'])
  xmin = int(df.iloc[i]['xmin'])
  ymax = int(df.iloc[i]['ymax'])
  ymin = int(df.iloc[i]['ymin'])
  txt = df.iloc[i]['name']

  x= xmax - xmin
  y = ymax - ymin 
  start_point = (xmin,ymin)
  end_point = (xmax,ymax)

  img = cv2.imread(directory+ '/'+image_path)


  image = cv2.putText(img, txt, org, font, 
               fontScale, color, thickness, cv2.LINE_AA)

  bbox_img = cv2.rectangle(image, start_point, end_point, color, thickness)

  cv2.imshow('image window', bbox_img)
  # add wait key. window waits until user presses a key
  cv2.waitKey(0)
  # and finally destroy/close all open windows
  cv2.destroyAllWindows()
$\endgroup$
4
  • $\begingroup$ what are you using to plot them? $\endgroup$
    – Dan
    Jan 9, 2023 at 15:23
  • $\begingroup$ simple script that I wrote $\endgroup$ Jan 9, 2023 at 15:27
  • 1
    $\begingroup$ what specific library are you using to plot them? Can you include code snippets? figuring out these specifics is essential to this problem since different plotting libraries can use many different paradigms to accomplish the same thing. $\endgroup$
    – Dan
    Jan 9, 2023 at 15:29
  • $\begingroup$ I have edited the post and included the code, I used cv2 $\endgroup$ Jan 9, 2023 at 15:42

1 Answer 1

0
$\begingroup$

Based on your answer, it looks like some of your bounding boxes use a different coordinate system than what is normally used for plotting in OpenCV. OpenCV treats the coordinates in the image as strictly positive (with $(0,0)$ being the top-left corner on the image when plotted) source.The fact that you have negative coordinates indicates that those coordinates use a different paradigm, e.g. that $(0,0)$ is in the center of the image.

You could look up what the formatting is for your dataset. It also might be simpler to re-normalize the image coordinates so that the lowest $x$ and $y$ values are $(0,0)$

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.