Skip to content

Commit

Permalink
添加相机参数信息
Browse files Browse the repository at this point in the history
  • Loading branch information
lsq210 committed Apr 9, 2021
1 parent bca2205 commit baf16f6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
6 changes: 5 additions & 1 deletion GTAVControler/Automation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@
using System.Drawing;
using System.Windows.Forms;
using GTA;
using Vector3 = GTA.Math.Vector3;


namespace GTAVControler
{
public class Automation
{
private static GTAVUtils.ROI[] GetRoIs(int width, int height)
{
Vector3 camPos = World.RenderingCamera.Position;
Vector3 camRot = World.RenderingCamera.Rotation;
Vehicle[] vehicles = World.GetAllVehicles();
List<GTAVUtils.ROI> rois = new List<GTAVUtils.ROI>();
foreach (Vehicle vehicle in vehicles)
{
GTAVUtils.ROI roi = new GTAVUtils.ROI(vehicle, (GTAVUtils.ROI.DetectionType)vehicle.ClassType, vehicle.Model.IsBigVehicle,rois.Count, width, height);
GTAVUtils.ROI roi = new GTAVUtils.ROI(vehicle, (GTAVUtils.ROI.DetectionType)vehicle.ClassType, vehicle.Model.IsBigVehicle,rois.Count, width, height, camPos, camRot);
if (roi.BBox.IsValid)
{
rois.Add(roi);
Expand Down
4 changes: 2 additions & 2 deletions GTAVControler/ModControler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Cotroler: Script
public Cotroler()
{
Tick += OnTick;
Interval = 4000;
Interval = 5000;
KeyDown += OnKeyDown;
Automation.Prepare();
}
Expand All @@ -21,7 +21,7 @@ private void OnTick(object sender, EventArgs e)
if (this.enableAutoSaveScreenshot)
{
Automation.Pause();
System.Threading.Thread.Sleep(2000);
System.Threading.Thread.Sleep(3000);
Automation.SaveGTAVData();
Automation.Resume();
}
Expand Down
15 changes: 12 additions & 3 deletions GTAVUtils/DataStructures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public static GTABoundingBox2 ComputeBoundingBox(Entity entity)

public class ROI
{
public ROI(Entity entity, DetectionType detectionType, bool isBigVehicle, int order, int imageWidth, int imageHeight)
public ROI(Entity entity, DetectionType detectionType, bool isBigVehicle, int order, int imageWidth, int imageHeight, Vector3 camPos, Vector3 camRot)
{
RoIEntity = entity;
Pos = new Vector3(entity.Position.X, entity.Position.Y, entity.Position.Z);
Expand All @@ -114,6 +114,8 @@ public ROI(Entity entity, DetectionType detectionType, bool isBigVehicle, int or
Order = order;
ImageWidth = imageWidth;
ImageHeight = imageHeight;
CamPos = camPos;
CamRot = camRot;
}

public ROI(ROI preROI)
Expand All @@ -126,6 +128,8 @@ public ROI(ROI preROI)
Order = preROI.Order;
ImageWidth = preROI.ImageWidth;
ImageHeight = preROI.ImageHeight;
CamPos = preROI.CamPos;
CamRot = preROI.CamRot;
}

public enum DetectionType
Expand Down Expand Up @@ -169,6 +173,10 @@ public enum DetectionType

public int ImageHeight { get; set; }

public Vector3 CamPos { get; }

public Vector3 CamRot { get; }

public int Order { get; }

private int GetWidth(float w)
Expand Down Expand Up @@ -263,8 +271,9 @@ public int ImageHight
public void Save(string imageName, string labelName, bool drawBBox = true)
{
GTAVManager.SaveImage(imageName, Image);

string txt = $"{Image.Width},{Image.Height}\n";
string imageSize = $"{Image.Width},{Image.Height}";
string camInfo = $"{RoIs[0].CamPos},{RoIs[0].CamRot}";
string txt = $"{imageSize}\n{camInfo}\n";
for (int i = 0; i < RoIs.Length; i++)
{
txt += RoIs[i].Serialize(true);
Expand Down

0 comments on commit baf16f6

Please sign in to comment.