Skip to content

Commit

Permalink
添加坐标转换 有问题
Browse files Browse the repository at this point in the history
  • Loading branch information
lsq210 committed Mar 24, 2021
1 parent ac4145a commit bcaedef
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 31 deletions.
9 changes: 5 additions & 4 deletions GTAVControler/Automation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ public static void SaveGTAVData()
// screenshot
Bitmap screenshot = GTAVUtils.Common.GetScreenshot();

// label
GTAVUtils.ROI[] labels = GetRoIs(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
// roilabel
GTAVUtils.ROI[] rois = GetRoIs(screenshot.Width, screenshot.Height);

// save data
new GTAVUtils.GTAVData(GTAVUtils.Common.CutScreenshot(screenshot), GTAVUtils.Common.FilterRoIs(labels)).Save(timestamp, timestamp);
// preprocess and save data
//GTAVUtils.Common.DataPreprocess(screenshot, rois).Save(timestamp, timestamp);
new GTAVUtils.GTAVData(screenshot, rois).Save(timestamp, timestamp);
}

public static void Pause()
Expand Down
47 changes: 28 additions & 19 deletions GTAVUtils/Common.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.IO;
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;
Expand All @@ -15,30 +15,39 @@ public static Bitmap GetScreenshot()
g.Dispose();
return screenshot;
}
public static ROI[] FilterRoIs(ROI[] rois)

public static GTAVData DataPreprocess(Bitmap screenshot, ROI[] RoIs)
{
// TODO: @lsq210
return rois;
// cutImage
int cutWidth = (int)(screenshot.Width * 0.1);
int cutHeight = (int)(screenshot.Height * 0.1);
Rectangle rect = new Rectangle(cutWidth, cutHeight, screenshot.Width - 2 * cutWidth, screenshot.Height - 2 * cutHeight);
Bitmap cutedScreenshot = screenshot.Clone(rect, System.Drawing.Imaging.PixelFormat.DontCare);

// filterRoIs
List<ROI> filteredRoIs = new List<ROI>();
foreach (ROI roi in rois)
foreach (ROI roi in RoIs)
{
roi.BBox.Min = new GTA.Math.Vector2(roi.BBox.Min.X - .1f, roi.BBox.Min.Y - .1f);
roi.BBox.Max = new GTA.Math.Vector2(roi.BBox.Max.X - .1f, roi.BBox.Max.Y - .1f);

if (roi.BBox.Min.X > 0 && roi.BBox.Min.Y > 0 && roi.BBox.Max.X > 0 && roi.BBox.Max.X > 0)
ROI filteredRoI = new ROI(roi)
{
ImageWidth = cutedScreenshot.Width,
ImageHeight = cutedScreenshot.Height
};
float ratio = roi.ImageWidth / filteredRoI.ImageWidth;
if(roi.BBox.Quality != GTABoundingBox2.DataQuality.Low)
{
filteredRoIs.Add(roi);
if (roi.BBox.Min.X > 0.1 && roi.BBox.Min.Y > 0.1)
{
if (roi.BBox.Max.X < 0.9 && roi.BBox.Max.Y < 0.9)
{
filteredRoI.BBox.Min = new GTA.Math.Vector2((roi.BBox.Min.X - .1f) * ratio, (roi.BBox.Min.Y - .1f) * ratio);
filteredRoI.BBox.Max = new GTA.Math.Vector2((roi.BBox.Max.X - .1f) * ratio, (roi.BBox.Max.Y - .1f) * ratio);
filteredRoIs.Add(filteredRoI);
}
}
}
}
return filteredRoIs.ToArray();
}

public static Bitmap CutScreenshot(Bitmap screenshot)
{
// TODO: @lsq210
Bitmap cutedScreenshot = screenshot;
return cutedScreenshot;
return new GTAVData(cutedScreenshot, filteredRoIs.ToArray());
}
}
}
27 changes: 19 additions & 8 deletions GTAVUtils/DataStructures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,26 @@ public static GTABoundingBox2 ComputeBoundingBox(Entity entity)

public class ROI
{
public ROI(Entity entity, DetectionType detectionType, int order, int originImageWidth, int originImageHeight)
public ROI(Entity entity, DetectionType detectionType, int order, int imageWidth, int imageHeight)
{
RoIEntity = entity;
Pos = new Vector3(entity.Position.X, entity.Position.Y, entity.Position.Z);
BBox = GTABoundingBox2.ComputeBoundingBox(entity);
Type = detectionType;
Order = order;
OriginImageWidth = originImageWidth;
OriginImageHeight = originImageHeight;
ImageWidth = imageWidth;
ImageHeight = imageHeight;
}

public ROI(ROI preROI)
{
RoIEntity = preROI.RoIEntity;
Pos = preROI.Pos;
BBox = preROI.BBox;
Type = preROI.Type;
Order = preROI.Order;
ImageWidth = preROI.ImageWidth;
ImageHeight = preROI.ImageHeight;
}

public enum DetectionType
Expand Down Expand Up @@ -136,27 +147,27 @@ public enum DetectionType
OpenWheel = 22
}

private Entity RoIEntity { get; }
public Entity RoIEntity { get; }

public Vector3 Pos { get; }

public GTABoundingBox2 BBox { get; }

public DetectionType Type { get; }

public int OriginImageWidth { get; }
public int ImageWidth { get; set; }

public int OriginImageHeight { get; }
public int ImageHeight { get; set; }

public int Order { get; }

private int GetWidth(float w)
{
return (int)(w * OriginImageWidth);
return (int)(w * ImageWidth);
}
private int GetHeight(float h)
{
return (int)(h * OriginImageHeight);
return (int)(h * ImageHeight);
}

public bool CheckVisible()
Expand Down

0 comments on commit bcaedef

Please sign in to comment.