Skip to content
This repository has been archived by the owner on Dec 7, 2021. It is now read-only.

Can vott read projects from files that has not been originally exported from it? #1055

Open
AhmedHisham1 opened this issue Jun 24, 2021 · 5 comments

Comments

@AhmedHisham1
Copy link

I have a dataset that has been annotated via multiple different annotation software, is it possible to write a script that converts them all into a vott supported format and read them as a new project? so that I can edit and re-annotate them inside vott?

@AhmedHisham1 AhmedHisham1 changed the title Is it possible to change some pre-annotated dataset into vott format and edit them in vott? Can vott read projects from files that has not been originally exported from it? Jun 24, 2021
@IanPNewson
Copy link

Yes, I've done it. I wrote a model in C# which can be used for this. Let me know if that would be any help and I'll look into uploading it to github.

@AhmedHisham1
Copy link
Author

Yes, that would be a great help. Thank you.

@IanPNewson
Copy link

Here you go:

https://github.com/IanPNewson/VottModel

It was just for my personal use so there's no documentation, and it only supports images, not video.

Here's some sample code that uses it:

    static async Task Main(string[] args)
    {

        var inDir = new DirectoryInfo(@"C:\Users\Ian\Documents\Projects\Output\StfcBot\StfcScreencopyOverlay");
        var dirPrefix = DateTime.Now.Ticks;

        {
            var outDir = inDir.Subdir($"{dirPrefix}.Predict_{predictThreshold}");

            var project = JsonConvert.DeserializeObject<Project>(File.ReadAllText(@"path to existing project"));
            project.name = outDir.Name;

            project.assets.Clear();
            project.sourceConnection.name = outDir.Name;
            project.targetConnection.name = outDir.Name;

            project.sourceConnection.providerOptions.folderPath =
                project.targetConnection.providerOptions.folderPath =
                    outDir.FullName;

            project.securityToken = null;
            project.useSecurityToken = false;

            var projectFile = outDir.File(outDir.Name + ".vott");

            var tasks = new List<Task>();

            foreach (var file in inDir.GetFiles("*.png"))
            {
                tasks.Add(Task.Run(() =>
                {
                    try
                    {
                        var assetImageFile = outDir.File(file.Name);
                        var assetFile = new AssetFile()
                        {
                            asset = new Asset()
                            {
                                name = file.Name,
                                format = "png",
                                path = "file:" + assetImageFile.FullName.Replace("\\", "/")
                            }
                        };

                        file.CopyTo(outDir.File(file.Name).FullName);

                        lock (project)
                            project.assets.Add(assetFile.asset.id, assetFile.asset);

                        assetFile.asset.size = new VottModel.Size
                        {
                            height = bmp.Height,
                            width = bmp.Width
                        };

                        swAssetFileGeneration.Start();
                        foreach (var result in json.Predictions)
                        {
                            var @class = result.Class;
                            var score = result.Score;
                            var rois = result.Bounds;

                            var rect = rois.ToRect(bmp.Size);

                            //g.DrawRectangle(Pens.Red, rect);
                            //g.DrawString(@class, new Font("Arial", 12), Brushes.Red, rect.Location);

                            assetFile.regions.Add(new Region
                            {
                                id = Guid.NewGuid().ToString().Substring(0, 8),
                                tags = new string[] { @class },
                                points = new VottModel.Point[]
                                {
                                new Point() { x = rect.Left, y = rect.Top },
                                new Point() { x = rect.Right, y = rect.Top },
                                new Point() { x = rect.Right, y = rect.Bottom },
                                new Point() { x = rect.Left, y = rect.Bottom }
                                },
                                boundingBox = new BoundingBox
                                {
                                    left = rect.Left,
                                    top = rect.Top,
                                    width = rect.Right - rect.Left,
                                    height = rect.Bottom - rect.Top
                                }
                            });
                        }

                        var assetFileFile = outDir.File($"{assetFile.asset.id}-asset.json");
                        File.WriteAllText(assetFileFile.FullName, JsonConvert.SerializeObject(assetFile, Formatting.Indented));
                        swAssetFileSave.Stop();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    swAssetFileGeneration.Stop();
                    ++count;
                    if (count % 10 == 0)
                    {
                        SaveProjectFile(project, projectFile);
                        Console.WriteLine($"{count} processed in {sw.ElapsedMilliseconds} ms, http: {swHttp.ElapsedMilliseconds / count}, json: {swJson.ElapsedMilliseconds / count}, gen: {swAssetFileGeneration.ElapsedMilliseconds / count}, filesave: {swAssetFileSave.ElapsedMilliseconds / count}");
                        sw.Restart();
                    }
                }));
            }
            await Task.WhenAll(tasks);

            SaveProjectFile(project, projectFile);
            Console.WriteLine($"Finished {outDir.Name}");
        }
        
        Console.WriteLine("All done creating vott projects");

        static void SaveProjectFile(Project project, FileInfo projectFile)
        {
            lock (project)
                File.WriteAllText(projectFile.FullName, JsonConvert.SerializeObject(project, Formatting.Indented));
        }
    }

@bdockbockd
Copy link

@AhmedHisham1 Did you solve it? Can you give me bit instruction how to achieve it?

@AhmedHisham1
Copy link
Author

Sorry for late reply. No I actually switched to CVAT by intel instead.

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

No branches or pull requests

3 participants