Skip to content

Commit bcaedef

Browse files
committed
添加坐标转换 有问题
1 parent ac4145a commit bcaedef

File tree

3 files changed

+52
-31
lines changed

3 files changed

+52
-31
lines changed

GTAVControler/Automation.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ public static void SaveGTAVData()
3434
// screenshot
3535
Bitmap screenshot = GTAVUtils.Common.GetScreenshot();
3636

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

40-
// save data
41-
new GTAVUtils.GTAVData(GTAVUtils.Common.CutScreenshot(screenshot), GTAVUtils.Common.FilterRoIs(labels)).Save(timestamp, timestamp);
40+
// preprocess and save data
41+
//GTAVUtils.Common.DataPreprocess(screenshot, rois).Save(timestamp, timestamp);
42+
new GTAVUtils.GTAVData(screenshot, rois).Save(timestamp, timestamp);
4243
}
4344

4445
public static void Pause()

GTAVUtils/Common.cs

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.IO;
1+
using System;
22
using System.Drawing;
33
using System.Windows.Forms;
44
using System.Collections.Generic;
@@ -15,30 +15,39 @@ public static Bitmap GetScreenshot()
1515
g.Dispose();
1616
return screenshot;
1717
}
18-
19-
public static ROI[] FilterRoIs(ROI[] rois)
18+
19+
public static GTAVData DataPreprocess(Bitmap screenshot, ROI[] RoIs)
2020
{
21-
// TODO: @lsq210
22-
return rois;
21+
// cutImage
22+
int cutWidth = (int)(screenshot.Width * 0.1);
23+
int cutHeight = (int)(screenshot.Height * 0.1);
24+
Rectangle rect = new Rectangle(cutWidth, cutHeight, screenshot.Width - 2 * cutWidth, screenshot.Height - 2 * cutHeight);
25+
Bitmap cutedScreenshot = screenshot.Clone(rect, System.Drawing.Imaging.PixelFormat.DontCare);
26+
27+
// filterRoIs
2328
List<ROI> filteredRoIs = new List<ROI>();
24-
foreach (ROI roi in rois)
29+
foreach (ROI roi in RoIs)
2530
{
26-
roi.BBox.Min = new GTA.Math.Vector2(roi.BBox.Min.X - .1f, roi.BBox.Min.Y - .1f);
27-
roi.BBox.Max = new GTA.Math.Vector2(roi.BBox.Max.X - .1f, roi.BBox.Max.Y - .1f);
28-
29-
if (roi.BBox.Min.X > 0 && roi.BBox.Min.Y > 0 && roi.BBox.Max.X > 0 && roi.BBox.Max.X > 0)
31+
ROI filteredRoI = new ROI(roi)
32+
{
33+
ImageWidth = cutedScreenshot.Width,
34+
ImageHeight = cutedScreenshot.Height
35+
};
36+
float ratio = roi.ImageWidth / filteredRoI.ImageWidth;
37+
if(roi.BBox.Quality != GTABoundingBox2.DataQuality.Low)
3038
{
31-
filteredRoIs.Add(roi);
39+
if (roi.BBox.Min.X > 0.1 && roi.BBox.Min.Y > 0.1)
40+
{
41+
if (roi.BBox.Max.X < 0.9 && roi.BBox.Max.Y < 0.9)
42+
{
43+
filteredRoI.BBox.Min = new GTA.Math.Vector2((roi.BBox.Min.X - .1f) * ratio, (roi.BBox.Min.Y - .1f) * ratio);
44+
filteredRoI.BBox.Max = new GTA.Math.Vector2((roi.BBox.Max.X - .1f) * ratio, (roi.BBox.Max.Y - .1f) * ratio);
45+
filteredRoIs.Add(filteredRoI);
46+
}
47+
}
3248
}
3349
}
34-
return filteredRoIs.ToArray();
35-
}
36-
37-
public static Bitmap CutScreenshot(Bitmap screenshot)
38-
{
39-
// TODO: @lsq210
40-
Bitmap cutedScreenshot = screenshot;
41-
return cutedScreenshot;
50+
return new GTAVData(cutedScreenshot, filteredRoIs.ToArray());
4251
}
4352
}
4453
}

GTAVUtils/DataStructures.cs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,26 @@ public static GTABoundingBox2 ComputeBoundingBox(Entity entity)
9898

9999
public class ROI
100100
{
101-
public ROI(Entity entity, DetectionType detectionType, int order, int originImageWidth, int originImageHeight)
101+
public ROI(Entity entity, DetectionType detectionType, int order, int imageWidth, int imageHeight)
102102
{
103103
RoIEntity = entity;
104104
Pos = new Vector3(entity.Position.X, entity.Position.Y, entity.Position.Z);
105105
BBox = GTABoundingBox2.ComputeBoundingBox(entity);
106106
Type = detectionType;
107107
Order = order;
108-
OriginImageWidth = originImageWidth;
109-
OriginImageHeight = originImageHeight;
108+
ImageWidth = imageWidth;
109+
ImageHeight = imageHeight;
110+
}
111+
112+
public ROI(ROI preROI)
113+
{
114+
RoIEntity = preROI.RoIEntity;
115+
Pos = preROI.Pos;
116+
BBox = preROI.BBox;
117+
Type = preROI.Type;
118+
Order = preROI.Order;
119+
ImageWidth = preROI.ImageWidth;
120+
ImageHeight = preROI.ImageHeight;
110121
}
111122

112123
public enum DetectionType
@@ -136,27 +147,27 @@ public enum DetectionType
136147
OpenWheel = 22
137148
}
138149

139-
private Entity RoIEntity { get; }
150+
public Entity RoIEntity { get; }
140151

141152
public Vector3 Pos { get; }
142153

143154
public GTABoundingBox2 BBox { get; }
144155

145156
public DetectionType Type { get; }
146157

147-
public int OriginImageWidth { get; }
158+
public int ImageWidth { get; set; }
148159

149-
public int OriginImageHeight { get; }
160+
public int ImageHeight { get; set; }
150161

151162
public int Order { get; }
152163

153164
private int GetWidth(float w)
154165
{
155-
return (int)(w * OriginImageWidth);
166+
return (int)(w * ImageWidth);
156167
}
157168
private int GetHeight(float h)
158169
{
159-
return (int)(h * OriginImageHeight);
170+
return (int)(h * ImageHeight);
160171
}
161172

162173
public bool CheckVisible()

0 commit comments

Comments
 (0)