Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read json file error #3

Open
tcotte opened this issue Nov 29, 2021 · 1 comment
Open

Read json file error #3

tcotte opened this issue Nov 29, 2021 · 1 comment

Comments

@tcotte
Copy link

tcotte commented Nov 29, 2021

I had an issue reading the JSON file. I think it isn't a good idea to use lists to read each lines in this case.
Therefore I changed the code and I suggest you to prefer dictionary research to retrieve the points (also it is less expensive because it is not necessary to read the picture).

In my case, I use rectangle bounding boxes and just one detection class :

with open(txt_path) as json_file:
        data = json.load(json_file)

        w = data["imageWidth"]
        h = data["imageHeight"]

        for idx, shapes in enumerate(data["shapes"]):
            x1 = shapes["points"][0][0]
            y1 = shapes["points"][0][1]
            x2 = shapes["points"][1][0]
            y2 = shapes["points"][1][1]

            cls = str(0) # just one class in my object detection project

            xmin = min(x1, x2)
            xmax = max(x1, x2)
            ymin = min(y1, y2)
            ymax = max(y1, y2)


            b = (xmin, xmax, ymin, ymax)
            bb = convert((w, h), b)

            txt_outfile.write(cls + " " + " ".join([str(a) for a in bb]) + '\n')
@visittor
Copy link

Agreed, using standard library is much more straightforward and easier to debug and modify than reading a file line-by-line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants