This repository was archived by the owner on Dec 30, 2025. It is now read-only.
forked from bradenhurl/GTAV_ObjectDetection
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObjectDetection.cpp
More file actions
2617 lines (2230 loc) · 109 KB
/
ObjectDetection.cpp
File metadata and controls
2617 lines (2230 loc) · 109 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#define NOMINMAX
#include "ObjectDetection.h"
#include "..\\ObjectDetIncludes.h"
#include <Windows.h>
#include <time.h>
#include <fstream>
#include <string>
#include <sstream>
#include "Functions.h"
#include "Constants.h"
#include <Eigen/Core>
#include <sstream>
#include "lodepng.h"
ObjectDetection::ObjectDetection()
{
}
ObjectDetection::~ObjectDetection()
{
}
//Global variable for storing camera parameters
CamParams s_camParams;
const float VERT_CAM_FOV = 59; //In degrees
//Need to input the vertical FOV with GTA functions.
//90 degrees horizontal (KITTI) corresponds to 59 degrees vertical (https://www.gtaall.com/info/fov-calculator.html).
const float HOR_CAM_FOV = 90; //In degrees
//Known stencil types
const int STENCIL_TYPE_DEFAULT = 0;//Ground, buildings, etc...
const int STENCIL_TYPE_NPC = 1;
const int STENCIL_TYPE_VEHICLE = 2;
const int STENCIL_TYPE_VEGETATION = 3;
const int STENCIL_TYPE_FLOOR = 4;//Seems to be floors and some boulevards
const int STENCIL_TYPE_SKY = 7;
const int STENCIL_TYPE_UNDERGROUND_ENTRANCE = 8;
const int STENCIL_TYPE_SELF = 129;
const int STENCIL_TYPE_OWNCAR = 130;
const std::vector<int> KNOWN_STENCIL_TYPES = { STENCIL_TYPE_DEFAULT, STENCIL_TYPE_NPC, STENCIL_TYPE_VEHICLE, STENCIL_TYPE_VEGETATION, STENCIL_TYPE_FLOOR, STENCIL_TYPE_SKY, STENCIL_TYPE_SELF, STENCIL_TYPE_OWNCAR, STENCIL_TYPE_UNDERGROUND_ENTRANCE };
const int PEDESTRIAN_CLASS_ID = 10;
const int CAR_CLASS_ID = 0;
void ObjectDetection::initCollection(UINT camWidth, UINT camHeight, bool exportEVE, int startIndex) {
if (m_initialized) {
return;
}
m_eve = exportEVE;
instance_index = startIndex;
ped = PLAYER::PLAYER_PED_ID();
m_ownVehicle = PED::GET_VEHICLE_PED_IS_IN(ped, false);
m_vehicle = m_ownVehicle;
setOwnVehicleObject();
char temp[] = "%06d";
char strComp[sizeof temp + 100];
sprintf(strComp, temp, instance_index);
instance_string = strComp;
s_camParams.width = (int)camWidth;
s_camParams.height = (int)camHeight;
//LOG(LL_ERR, "Testing4");
//Need to set camera params
s_camParams.init = false;
camera = CAM::GET_RENDERING_CAM();
//Create camera intrinsics matrix
calcCameraIntrinsics();
pointclouds = true;
collectTracking = false;
//Export directory
log("Before getting export dir");
baseFolder = std::string(getenv("DEEPGTAV_EXPORT_DIR")) + "\\";
CreateDirectory(baseFolder.c_str(), NULL);
if (exportEVE) {
baseFolder += "eve\\";
}
if (collectTracking) {
baseFolder += "tracking\\";
}
else {
baseFolder += "object\\";
}
log("After getting export dir");
CreateDirectory(baseFolder.c_str(), NULL);
m_timeTrackFile = baseFolder + "\\TimeAnalysis.txt";
m_usedPixelFile = baseFolder + "\\UsedPixels.txt";
log("After getting export dir2");
//Overwrite previous time analysis file so it is empty
FILE* f = fopen(m_timeTrackFile.c_str(), "w");
std::ostringstream oss;
oss << "Mean err, var, avg speed, avg dist";
oss << "\nResults are in metres. Frames attempted to capture at 10 Hz.";
std::string str = oss.str();
fprintf(f, str.c_str());
fprintf(f, "\n");
fclose(f);
//Overwrite previous stencil pixel used file so it is empty
f = fopen(m_usedPixelFile.c_str(), "w");
std::ostringstream oss1;
oss1 << "Unused pixels, index, series (if tracking)";
std::string str1 = oss1.str();
fprintf(f, str1.c_str());
fprintf(f, "\n");
fclose(f);
log("Before initVehicleLookup");
initVehicleLookup();
//Setup LiDAR before collecting
setupLiDAR();
m_initialized = true;
}
//Set own object info for exporting position_world
void ObjectDetection::setOwnVehicleObject() {
Vector3 min, max;
Hash model = ENTITY::GET_ENTITY_MODEL(m_ownVehicle);
Vector3 dim = getVehicleDims(m_ownVehicle, model, min, max);
m_ownVehicleObj = ObjEntity(m_ownVehicle);
//Fill out info for own car
m_ownVehicleObj.objType = "Car";
float kittiHeight = 2 * dim.z;
float kittiWidth = 2 * dim.x;
float kittiLength = 2 * dim.y;
m_ownVehicleObj.width = kittiWidth;
m_ownVehicleObj.height = kittiHeight;
m_ownVehicleObj.length = kittiLength;
Vector3 position;
position.x = 0;
position.y = 0;
position.z = 0;
m_ownVehicleObj.location = position;
m_ownVehicleObj.rotation_y = -1;
m_ownVehicleObj.alpha = -1;
BBox2D bbox2d;
bbox2d.bottom = -1;
bbox2d.top = -1;
bbox2d.left = -1;
bbox2d.right = -1;
m_ownVehicleObj.bbox2d = bbox2d;
m_ownVehicleObj.truncation = -1;
m_ownVehicleObj.occlusion = -1;
m_ownVehicleObj.modelString = VEHICLE::GET_DISPLAY_NAME_FROM_VEHICLE_MODEL(model);
m_ownVehicleObj.speed = -1;
m_ownVehicleObj.roll = -1;
m_ownVehicleObj.pitch = -1;
m_ownVehicleObj.pointsHit2D = -1;
m_ownVehicleObj.pointsHit3D = -1;
}
//For updating all depth/stencil related variables when depth/stencil buffer are one frame after game functions
FrameObjectInfo ObjectDetection::setDepthAndStencil(bool prevDepth, float* pDepth, uint8_t* pStencil) {
if (prevDepth) {
m_pDepth = pDepth;
m_pStencil = pStencil;
}
else {
setFilenames();
}
if (lidar_initialized) setDepthBuffer(prevDepth);
if (lidar_initialized) setStencilBuffer();
if (prevDepth) {
if (lidar_initialized) printSegImage();
if (lidar_initialized) outputOcclusion();
if (lidar_initialized) outputUnusedStencilPixels();
}
return m_curFrame;
}
FrameObjectInfo ObjectDetection::generateMessage(float* pDepth, uint8_t* pStencil, int entityID) {
//LOG(LL_ERR, "Depth data generate: ", pDepth[0], pDepth[1], pDepth[2], pDepth[3], pDepth[4], pDepth[5], pDepth[6], pDepth[7]);
m_pDepth = pDepth;
m_pStencil = pStencil;
m_vPerspective = entityID;
if (entityID != -1) {
m_vehicle = entityID;
}
else {
m_vehicle = m_ownVehicle;
}
//TODO pass this through
bool depthMap = true;
setIndex();
setPosition();
outputRealSpeed();
setDepthAndStencil();
//Need to set peds list first for integrating peds on bikes
setPedsList();
setVehiclesList();
setSpeed();
setYawRate();
setTime();
setFocalLength();
log("After focalLength");
//Update 2D bboxes, and create segmentation of stencil values
processSegmentation2D();
processSegmentation3D();
processOcclusion();
if (pointclouds && lidar_initialized) collectLiDAR();
update3DPointsHit();
if (depthMap && lidar_initialized) printSegImage();
log("After printSeg");
if (depthMap && lidar_initialized) outputOcclusion();
log("After output occlusion");
if (depthMap && lidar_initialized) outputUnusedStencilPixels();
log("After output unused stencil");
setGroundPlanePoints();
return m_curFrame;
}
//Returns the angle between a relative position vector and the forward vector (rotated about up axis)
float ObjectDetection::observationAngle(Vector3 position) {
float x1 = m_camRightVector.x;
float y1 = m_camRightVector.y;
float z1 = m_camRightVector.z;
float x2 = position.x;
float y2 = position.y;
float z2 = position.z;
float xn = m_camUpVector.x;
float yn = m_camUpVector.y;
float zn = m_camUpVector.z;
float dot = x1 * x2 + y1 * y2 + z1 * z2;
float det = x1 * y2*zn + x2 * yn*z1 + xn * y1*z2 - z1 * y2*xn - z2 * yn*x1 - zn * y1*x2;
float observationAngle = atan2(det, dot);
if (DEBUG_LOGGING) {
std::ostringstream oss;
oss << "Forward is: " << x1 << ", " << y1 << ", " << z1 <<
"\nNormal is: " << x2 << ", " << y2 << ", " << z2 <<
"\nPosition is: " << position.x << ", " << position.y << ", " << position.z << " and angle is: " << observationAngle;
std::string str = oss.str();
log(str);
}
return observationAngle;
}
void ObjectDetection::drawVectorFromPosition(Vector3 vector, int blue, int green) {
GRAPHICS::DRAW_LINE(s_camParams.pos.x, s_camParams.pos.y, s_camParams.pos.z, vector.x * 1000 + s_camParams.pos.x, vector.y * 1000 + s_camParams.pos.y, vector.z * 1000 + s_camParams.pos.z, 0, green, blue, 200);
WAIT(0);
}
//Saves the position and vectors of the capture vehicle
void ObjectDetection::setPosition() {
//NOTE: The forward and right vectors are swapped (compared to native function labels) to keep consistency with coordinate system
if (m_eve) {
ENTITY::GET_ENTITY_MATRIX(m_vehicle, &vehicleForwardVector, &vehicleRightVector, &vehicleUpVector, ¤tPos); //Blue or red pill
/*LOG(LL_ERR, "Eve Forward vector: ", m_camForwardVector.x, " Y: ", m_camForwardVector.y, " Z: ", m_camForwardVector.z);
LOG(LL_ERR, "Forward vector: ", vehicleForwardVector.x, " Y: ", vehicleForwardVector.y, " Z: ", vehicleForwardVector.z);
LOG(LL_ERR, "Right vector: ", vehicleRightVector.x, " Y: ", vehicleRightVector.y, " Z: ", vehicleRightVector.z);
LOG(LL_ERR, "Up vector: ", vehicleUpVector.x, " Y: ", vehicleUpVector.y, " Z: ", vehicleUpVector.z);
LOG(LL_ERR, "Cam Forward vector: ", m_camForwardVector.x, " Y: ", m_camForwardVector.y, " Z: ", m_camForwardVector.z);
LOG(LL_ERR, "Cam Right vector: ", m_camRightVector.x, " Y: ", m_camRightVector.y, " Z: ", m_camRightVector.z);
LOG(LL_ERR, "Cam Up vector: ", m_camUpVector.x, " Y: ", m_camUpVector.y, " Z: ", m_camUpVector.z);
LOG(LL_ERR, "Curr position: ", s_camParams.pos.x, " Y: ", s_camParams.pos.y, " Z: ", s_camParams.pos.z);
LOG(LL_ERR, "Theta: ", s_camParams.theta.x, " Y: ", s_camParams.theta.y, " Z: ", s_camParams.theta.z);*/
float ogThetaZ = tan(-vehicleForwardVector.x / vehicleForwardVector.y) * 180 / PI;
float newThetaZ = tan(-m_camForwardVector.x / m_camForwardVector.y) * 180 / PI;
float ogThetaZ2 = atan2(-vehicleForwardVector.x, vehicleForwardVector.y) * 180 / PI;
float newThetaZ2 = atan2(-m_camForwardVector.x, m_camForwardVector.y) * 180 / PI;
float ogThetaX2 = atan2(vehicleForwardVector.z, sqrt(pow(vehicleForwardVector.y, 2) + pow(vehicleForwardVector.x, 2))) * 180 / PI;
float newThetaX2 = atan2(m_camForwardVector.z, sqrt(pow(m_camForwardVector.y, 2) + pow(m_camForwardVector.x, 2))) * 180 / PI;
float ogThetaX = tan(vehicleForwardVector.z / sqrt(pow(vehicleForwardVector.y, 2) + pow(vehicleForwardVector.x, 2))) * 180 / PI;
float newThetaX = tan(m_camForwardVector.z / sqrt(pow(m_camForwardVector.y, 2) + pow(m_camForwardVector.x, 2))) * 180 / PI;
//LOG(LL_ERR, "Theta og/new Z: ", ogThetaZ, ", ", newThetaZ, " og/new Z2: ", ogThetaZ2, ", ", newThetaZ2, " og, new X: ", ogThetaX, ", ", newThetaX, " og, new ThetaX2: ", ogThetaX2, ", ", newThetaX2);
float ogThetaY2 = atan2(vehicleRightVector.z, sqrt(pow(vehicleRightVector.y, 2) + pow(vehicleRightVector.x, 2))) * 180 / PI;
float newThetaY2 = atan2(-m_camRightVector.z, sqrt(pow(m_camRightVector.y, 2) + pow(m_camRightVector.x, 2))) * 180 / PI;
//LOG(LL_ERR, "Theta og/new Y2: ", ogThetaY2, ", ", newThetaY2);
s_camParams.theta.x = newThetaX2;
s_camParams.theta.y = newThetaY2;
s_camParams.theta.z = newThetaZ2;
//LOG(LL_ERR, "Theta: ", s_camParams.theta.x, " Y: ", s_camParams.theta.y, " Z: ", s_camParams.theta.z);
}
else {
//If not eve, the camera and vehicle are aligned by pausing and flushing the buffers
ENTITY::GET_ENTITY_MATRIX(m_vehicle, &m_camForwardVector, &m_camRightVector, &m_camUpVector, ¤tPos);
ENTITY::GET_ENTITY_MATRIX(m_vehicle, &vehicleForwardVector, &vehicleRightVector, &vehicleUpVector, ¤tPos); //Blue or red pill
}
m_curFrame.position = currentPos;
m_curFrame.roll = atan2(-vehicleRightVector.z, sqrt(pow(vehicleRightVector.y, 2) + pow(vehicleRightVector.x, 2)));
m_curFrame.pitch = atan2(-vehicleForwardVector.z, sqrt(pow(vehicleForwardVector.y, 2) + pow(vehicleForwardVector.x, 2)));
//Should use atan2 over gameplay heading
//float heading = GAMEPLAY::GET_HEADING_FROM_VECTOR_2D(vehicleForwardVector.x, vehicleForwardVector.y);
m_curFrame.heading = atan2(vehicleForwardVector.y, vehicleForwardVector.x);
m_curFrame.forwardVec = vehicleForwardVector;
m_curFrame.upVec = vehicleUpVector;
m_curFrame.rightVec = vehicleRightVector;
m_curFrame.camPos = s_camParams.pos;
//Check if we see it (not occluded)
Vector3 min, max, offcenter;
Hash model = ENTITY::GET_ENTITY_MODEL(m_vehicle);
GAMEPLAY::GET_MODEL_DIMENSIONS(model, &min, &max);
Vector3 kittiWorldPos = correctOffcenter(currentPos, min, max, vehicleForwardVector, vehicleRightVector, vehicleUpVector, offcenter);
m_curFrame.kittiWorldPos = kittiWorldPos;
}
void ObjectDetection::setSpeed() {
m_curFrame.speed = ENTITY::GET_ENTITY_SPEED(m_vehicle);
}
void ObjectDetection::setYawRate() {
Vector3 rates = ENTITY::GET_ENTITY_ROTATION_VELOCITY(m_vehicle);
m_curFrame.yawRate = rates.z*180.0 / 3.14159265359;
}
void ObjectDetection::setTime() {
m_curFrame.timeHours = TIME::GET_CLOCK_HOURS();
}
//Cycle through 8 corners of bbox and see if the ray makes it to or past this point
bool ObjectDetection::hasLOSToEntity(Entity entityID, Vector3 position, Vector3 dim, Vector3 forwardVector, Vector3 rightVector, Vector3 upVector, bool useOrigin, Vector3 origin) {
Vector3 oPos;
if (useOrigin) {
oPos = origin;
}
else {
oPos = s_camParams.pos;
}
for (int right = -1; right <= 1; right += 2) {
for (int forward = -1; forward <= 1; forward += 2) {
for (int up = -1; up <= 1; up += 2) {
Vector3 pos;
pos.x = position.x + forward * dim.y*forwardVector.x + right * dim.x*rightVector.x + up * dim.z*upVector.x;
pos.y = position.y + forward * dim.y*forwardVector.y + right * dim.x*rightVector.y + up * dim.z*upVector.y;
pos.z = position.z + forward * dim.y*forwardVector.z + right * dim.x*rightVector.z + up * dim.z*upVector.z;
Vector3 relPos;
relPos.x = pos.x - oPos.x;
relPos.y = pos.y - oPos.y;
relPos.z = pos.z - oPos.z;
BOOL isHit;
Entity hitEntity;
Vector3 target, endCoord, surfaceNorm;
target.x = relPos.x * 200 + pos.x;
target.y = relPos.y * 200 + pos.y;
target.z = relPos.z * 200 + pos.z;
//options: -1=everything
//New function is called _START_SHAPE_TEST_RAY
int raycast_handle = WORLDPROBE::_CAST_RAY_POINT_TO_POINT(oPos.x, oPos.y, oPos.z, target.x, target.y, target.z, -1, m_vehicle, 7);
//New function is called GET_SHAPE_TEST_RESULT
WORLDPROBE::_GET_RAYCAST_RESULT(raycast_handle, &isHit, &endCoord, &surfaceNorm, &hitEntity);
float distance = sqrt(SYSTEM::VDIST2(oPos.x, oPos.y, oPos.z, pos.x, pos.y, pos.z));
float rayDistance = sqrt(SYSTEM::VDIST2(oPos.x, oPos.y, oPos.z, endCoord.x, endCoord.y, endCoord.z));
if (!isHit || rayDistance > distance) {
return true;
}
}
}
}
return false;
}
BBox2D ObjectDetection::BBox2DFrom3DObject(Vector3 position, Vector3 dim, Vector3 forwardVector, Vector3 rightVector, Vector3 upVector, bool &success, float &truncation) {
//Adjust position back to middle of the object for calculating 2D bounding box (Kitti has it at bottom)
position.z += dim.z;
BBox2D bbox2d;
bbox2d.left = 1.0;// width;
bbox2d.right = 0.0;
bbox2d.top = 1.0;// height;
bbox2d.bottom = 0.0;
for (int right = -1; right <= 1; right += 2) {
for (int forward = -1; forward <= 1; forward += 2) {
for (int up = -1; up <= 1; up += 2) {
Vector3 pos;
pos.x = position.x + forward * dim.y*forwardVector.x + right * dim.x*rightVector.x + up * dim.z*upVector.x;
pos.y = position.y + forward * dim.y*forwardVector.y + right * dim.x*rightVector.y + up * dim.z*upVector.y;
pos.z = position.z + forward * dim.y*forwardVector.z + right * dim.x*rightVector.z + up * dim.z*upVector.z;
float screenX, screenY;
//This function always returns false, do not worry about return value
bool success = GRAPHICS::_WORLD3D_TO_SCREEN2D(pos.x, pos.y, pos.z, &screenX, &screenY);
std::ostringstream oss2;
oss2 << "\nnew ScreenX: " << screenX << " ScreenY: " << screenY;
std::string str2 = oss2.str();
log(str2);
//Calculate with eigen if off-screen
Eigen::Vector3f pt(pos.x, pos.y, pos.z);
if (screenX < 0 || screenX > 1 || screenY < 0 || screenY > 1) {
Eigen::Vector2f uv = get_2d_from_3d(pt);
screenX = uv(0);
screenY = uv(1);
}
if (CORRECT_2D_POINTS_BEHIND_CAMERA) {
//Corrections for points which are behind camera
Vector3 relativePos;
relativePos.x = pos.x - s_camParams.pos.x;
relativePos.y = pos.y - s_camParams.pos.y;
relativePos.z = pos.z - s_camParams.pos.z;
relativePos = convertCoordinateSystem(relativePos, m_camForwardVector, m_camRightVector, m_camUpVector);
//If behind camera update left/right bounds to reflect its position
if (relativePos.y < 0) {
if (relativePos.x > 0) {
screenX = 1.0;
}
else {
screenX = 0.0;
}
}
}
//Update if value outside current box
if (screenX < bbox2d.left) bbox2d.left = screenX;
if (screenX > bbox2d.right) bbox2d.right = screenX;
if (screenY < bbox2d.top) bbox2d.top = screenY;
if (screenY > bbox2d.bottom) bbox2d.bottom = screenY;
}
}
}
//Calculate truncation
float absL = std::max<float>(0, bbox2d.left);
float absR = std::min<float>(1, bbox2d.right);
float absT = std::max<float>(0, bbox2d.top);
float absB = std::min<float>(1, bbox2d.bottom);
float areaInside = (absR - absL) * (absB - absT);
float areaTotal = (bbox2d.right - bbox2d.left) * (bbox2d.bottom - bbox2d.top);
truncation = 1 - (areaInside / areaTotal);
//Set bbox boundaries
bbox2d.left = std::max(0.0f, bbox2d.left);
bbox2d.right = std::min(1.0f, bbox2d.right);
bbox2d.top = std::max(0.0f, bbox2d.top);
bbox2d.bottom = std::min(1.0f, bbox2d.bottom);
//Entire object is out of bounds - do not count
if (bbox2d.left == bbox2d.right || bbox2d.top == bbox2d.bottom) {
success = false;
return bbox2d;
}
std::ostringstream oss2;
oss2 << "BBox left: " << bbox2d.left << " right: " << bbox2d.right << " top: " << bbox2d.top << " bot: " << bbox2d.bottom << std::endl <<
"PosX: " << bbox2d.posX() << " PosY: " << bbox2d.posY() << " Width: " << bbox2d.width() << " Height: " << bbox2d.height();
std::string str2 = oss2.str();
log(str2);
return bbox2d;
}
bool ObjectDetection::checkDirection(Vector3 unit, Vector3 point, Vector3 min, Vector3 max) {
float dotPoint = dotProd(point, unit);
float dotMax = dotProd(max, unit);
float dotMin = dotProd(min, unit);
if ((dotMax <= dotPoint && dotPoint <= dotMin) ||
(dotMax >= dotPoint && dotPoint >= dotMin)) {
return true;
}
return false;
}
//Point and objPos should be in world coordinates
void ObjectDetection::setEntityBBoxParameters(ObjEntity *e) {
//Added BBOX_ADJUSTMENT_FACTOR as detailed models sometimes go outside 3D bboxes
Vector3 forward; forward.y = e->dim.y * BBOX_ADJUSTMENT_FACTOR; forward.x = 0; forward.z = 0;
forward = convertCoordinateSystem(forward, e->yVector, e->xVector, e->zVector);
Vector3 right; right.x = e->dim.x * BBOX_ADJUSTMENT_FACTOR; right.y = 0; right.z = 0;
right = convertCoordinateSystem(right, e->yVector, e->xVector, e->zVector);
Vector3 up; up.z = e->dim.z; up.x = 0; up.y = 0;
up = convertCoordinateSystem(up, e->yVector, e->xVector, e->zVector);
//position is given at bottom of bounding box (as per kitti)
Vector3 objPos = e->worldPos;
e->rearBotLeft.x = objPos.x - forward.x - right.x - up.x * (BBOX_ADJUSTMENT_FACTOR - 1);
e->rearBotLeft.y = objPos.y - forward.y - right.y - up.y * (BBOX_ADJUSTMENT_FACTOR - 1);
e->rearBotLeft.z = objPos.z - forward.z - right.z - up.z * (BBOX_ADJUSTMENT_FACTOR - 1);
e->frontBotLeft.x = objPos.x + forward.x - right.x - up.x * (BBOX_ADJUSTMENT_FACTOR - 1);
e->frontBotLeft.y = objPos.y + forward.y - right.y - up.y * (BBOX_ADJUSTMENT_FACTOR - 1);
e->frontBotLeft.z = objPos.z + forward.z - right.z - up.z * (BBOX_ADJUSTMENT_FACTOR - 1);
e->rearTopLeft.x = objPos.x - forward.x - right.x + 2 * up.x + up.x * BBOX_ADJUSTMENT_FACTOR;
e->rearTopLeft.y = objPos.y - forward.y - right.y + 2 * up.y + up.y * BBOX_ADJUSTMENT_FACTOR;
e->rearTopLeft.z = objPos.z - forward.z - right.z + 2 * up.z + up.z * BBOX_ADJUSTMENT_FACTOR;
e->rearBotRight.x = objPos.x - forward.x + right.x - up.x * (BBOX_ADJUSTMENT_FACTOR - 1);
e->rearBotRight.y = objPos.y - forward.y + right.y - up.y * (BBOX_ADJUSTMENT_FACTOR - 1);
e->rearBotRight.z = objPos.z - forward.z + right.z - up.z * (BBOX_ADJUSTMENT_FACTOR - 1);
e->rearMiddleLeft.x = objPos.x - forward.x - right.x + up.x;
e->rearMiddleLeft.y = objPos.y - forward.y - right.y + up.y;
e->rearMiddleLeft.z = objPos.z - forward.z - right.z + up.z;
e->rearThirdLeft.x = objPos.x - forward.x - right.x + 2 / 3 * up.x;
e->rearThirdLeft.y = objPos.y - forward.y - right.y + 2 / 3 * up.y;
e->rearThirdLeft.z = objPos.z - forward.z - right.z + 2 / 3 * up.z;
e->rearTopExactLeft.x = objPos.x - forward.x - right.x + 2 * up.x;
e->rearTopExactLeft.y = objPos.y - forward.y - right.y + 2 * up.y;
e->rearTopExactLeft.z = objPos.z - forward.z - right.z + 2 * up.z;
e->u = getUnitVector(subtractVecs(e->frontBotLeft, e->rearBotLeft));
e->v = getUnitVector(subtractVecs(e->rearTopLeft, e->rearBotLeft));
e->w = getUnitVector(subtractVecs(e->rearBotRight, e->rearBotLeft));
}
//Return true if pixel (i,j) is inside the entity's unprocessed 2D bounding box
bool ObjectDetection::in2DBoxUnprocessed(const int &i, const int &j, ObjEntity* e) {
if (i < e->bbox2dUnprocessed.left) return false;
if (i > e->bbox2dUnprocessed.right) return false;
if (j < e->bbox2dUnprocessed.top) return false;
if (j > e->bbox2dUnprocessed.bottom) return false;
return true;
}
//Point and objPos should be in world coordinates
bool ObjectDetection::in3DBox(Vector3 point, Vector3 objPos, Vector3 dim, Vector3 yVector, Vector3 xVector, Vector3 zVector) {
Vector3 forward; forward.y = dim.y; forward.x = 0; forward.z = 0;
forward = convertCoordinateSystem(forward, yVector, xVector, zVector);
Vector3 right; right.x = dim.x; right.y = 0; right.z = 0;
right = convertCoordinateSystem(right, yVector, xVector, zVector);
Vector3 up; up.z = dim.z; up.x = 0; up.y = 0;
up = convertCoordinateSystem(up, yVector, xVector, zVector);
Vector3 rearBotLeft;
rearBotLeft.x = objPos.x - forward.x - right.x - up.x;
rearBotLeft.y = objPos.y - forward.y - right.y - up.y;
rearBotLeft.z = objPos.z - forward.z - right.z - up.z;
Vector3 frontBotLeft;
frontBotLeft.x = objPos.x + forward.x - right.x - up.x;
frontBotLeft.y = objPos.y + forward.y - right.y - up.y;
frontBotLeft.z = objPos.z + forward.z - right.z - up.z;
Vector3 rearTopLeft;
rearTopLeft.x = objPos.x - forward.x - right.x + up.x;
rearTopLeft.y = objPos.y - forward.y - right.y + up.y;
rearTopLeft.z = objPos.z - forward.z - right.z + up.z;
Vector3 rearBotRight;
rearBotRight.x = objPos.x - forward.x + right.x - up.x;
rearBotRight.y = objPos.y - forward.y + right.y - up.y;
rearBotRight.z = objPos.z - forward.z + right.z - up.z;
std::ostringstream oss2;
oss2 << " rearBotLeft are: " << rearBotLeft.x << ", " << rearBotLeft.y << ", " << rearBotLeft.z;
oss2 << "\nfrontBotLeft: " << frontBotLeft.x << ", " << frontBotLeft.y << ", " << frontBotLeft.z;
oss2 << "\nrearTopLeft: " << rearTopLeft.x << ", " << rearTopLeft.y << ", " << rearTopLeft.z;
oss2 << "\nrearBotRight: " << rearBotRight.x << ", " << rearBotRight.y << ", " << rearBotRight.z;
oss2 << "\ndim: " << dim.x << ", " << dim.y << ", " << dim.z;
std::string str2 = oss2.str();
log(str2);
Vector3 u = getUnitVector(subtractVecs(frontBotLeft, rearBotLeft));
Vector3 v = getUnitVector(subtractVecs(rearTopLeft, rearBotLeft));
Vector3 w = getUnitVector(subtractVecs(rearBotRight, rearBotLeft));
if (!checkDirection(u, point, rearBotLeft, frontBotLeft)) return false;
if (!checkDirection(v, point, rearBotLeft, rearTopLeft)) return false;
if (!checkDirection(w, point, rearBotLeft, rearBotRight)) return false;
return true;
}
//Takes in an entity and a point (in world coordinates) and returns true if the point resides within the
//entity's 3D bounding box.
//Note: Need to set the entity's parameters u,v,w, and rearBotLeft, etc...
bool ObjectDetection::in3DBox(ObjEntity* e, Vector3 point, bool &upperHalf) {
upperHalf = false;
if (checkDirection(e->v, point, e->rearMiddleLeft, e->rearTopExactLeft)) upperHalf = true;
if (!checkDirection(e->u, point, e->rearBotLeft, e->frontBotLeft)) return false;
if (!checkDirection(e->v, point, e->rearBotLeft, e->rearTopLeft)) return false;
if (!checkDirection(e->w, point, e->rearBotLeft, e->rearBotRight)) return false;
return true;
}
bool ObjectDetection::isPointOccluding(Vector3 worldPos, ObjEntity *e) {
//Need to test in3DBox as stencil buffer goes through windows but depth buffer does not
bool upperHalf;
if (in3DBox(e, worldPos, upperHalf)) {
return false;
}
float pointDist = sqrt(SYSTEM::VDIST2(s_camParams.pos.x, s_camParams.pos.y, s_camParams.pos.z, worldPos.x, worldPos.y, worldPos.z));
float distObjCenter = sqrt(SYSTEM::VDIST2(s_camParams.pos.x, s_camParams.pos.y, s_camParams.pos.z, e->worldPos.x, e->worldPos.y, e->worldPos.z));
//Point needs to be closer
if (pointDist < distObjCenter) {
float groundZ;
GAMEPLAY::GET_GROUND_Z_FOR_3D_COORD(worldPos.x, worldPos.y, worldPos.z + 0.5, &(groundZ), 0);
//Check it is not the ground in the image (or the ground is much higher/lower than the object)
if ((groundZ + GROUND_POINT_MAX_DIST) < worldPos.z || s_camParams.pos.z > (e->worldPos.z + 4) || s_camParams.pos.z < (e->worldPos.z - 2)) {
return true;
}
}
return false;
}
//TODO Need to fix this now that we know stencil/depth buffers do not align
//The problem is that depth buffer hits vehicle windows.
//The stencil buffer goes through the vehicle windows and captures whatever is behind them.
//This makes it difficult for segmentation and 2D vs 3D segmentation will be different.
void ObjectDetection::processSegmentation2D() {
/*for (int j = 0; j < s_camParams.height; ++j) {
for (int i = 0; i < s_camParams.width; ++i) {
uint8_t stencilVal = m_pStencil[j * s_camParams.width + i];
if (stencilVal == STENCIL_TYPE_VEHICLE || stencilVal == STENCIL_TYPE_NPC) {
processStencilPixel2D(stencilVal, j, i, xVectorCam, yVectorCam, zVectorCam);
}
else if (stencilVal == STENCIL_TYPE_OWNCAR) {
addPointTo2DSegImages(i, j, m_ownVehicle);
}
}
}
processOverlappingPoints2D();*/
}
void ObjectDetection::processSegmentation3D() {
//Converting vehicle dimensions from vehicle to world coordinates for offset position
Vector3 worldX; worldX.x = 1; worldX.y = 0; worldX.z = 0;
Vector3 worldY; worldY.x = 0; worldY.y = 1; worldY.z = 0;
Vector3 worldZ; worldZ.x = 0; worldZ.y = 0; worldZ.z = 1;
Vector3 xVectorCam = convertCoordinateSystem(worldX, m_camForwardVector, m_camRightVector, m_camUpVector);
Vector3 yVectorCam = convertCoordinateSystem(worldY, m_camForwardVector, m_camRightVector, m_camUpVector);
Vector3 zVectorCam = convertCoordinateSystem(worldZ, m_camForwardVector, m_camRightVector, m_camUpVector);
//Create depth array to use later
for (int j = 0; j < s_camParams.height; ++j) {
for (int i = 0; i < s_camParams.width; ++i) {
float ndc = m_pDepth[j * s_camParams.width + i];
Vector3 relPos = depthToCamCoords(ndc, i, j);
float distance = sqrt(SYSTEM::VDIST2(0, 0, 0, relPos.x, relPos.y, relPos.z));
m_depthMat.at<float>(j, i) = distance;
}
}
//Set the bounding box parameters (for reducing # of calculations per pixel)
for (auto &entry : m_curFrame.vehicles) {
setEntityBBoxParameters(&entry.second);
}
for (auto &entry : m_curFrame.peds) {
setEntityBBoxParameters(&entry.second);
}
for (int j = 0; j < s_camParams.height; ++j) {
for (int i = 0; i < s_camParams.width; ++i) {
uint8_t stencilVal = m_pStencil[j * s_camParams.width + i];
if (stencilVal == STENCIL_TYPE_OWNCAR) {
addPointToSegImages(i, j, m_ownVehicle);
}
else {
processStencilPixel3D(stencilVal, j, i, xVectorCam, yVectorCam, zVectorCam);
}
}
}
if (PROCESS_OVERLAPPING_POINTS) {
processOverlappingPoints();
}
}
//Goes through points which were in multiple 3D boxes (overlapping points)
//Uses opencv to flood fill all points for sets of entities which have overlapping points
//If filled areas have a unique entityID (other than the overlapping points), entire area gets set to the unique entityID
//TODO: Step 2: find contour with depth for areas which have more than a single unique entityID
void ObjectDetection::processOverlappingPoints() {
//Create mask with only points from overlapping entities
//Process one set of entity IDs at a time
while (!m_overlappingPoints.empty()) {
std::vector<ObjEntity*> objEntities = m_overlappingPoints.begin()->second;
int ptIdx = m_overlappingPoints.begin()->first;
int stencilType = STENCIL_TYPE_VEHICLE;
if (objEntities[0]->objType == "Pedestrian") {
stencilType = STENCIL_TYPE_NPC;
}
//Initialize mask
cv::Mat allPointsMask = cv::Mat::zeros(cv::Size(s_camParams.width, s_camParams.height), CV_8U);
//Create mask of all points from overlapping entities
for (int j = 0; j < s_camParams.height; ++j) {
for (int i = 0; i < s_camParams.width; ++i) {
int idx = j * s_camParams.width + i;
uint8_t stencilVal = m_pStencil[idx];
if (stencilVal == stencilType) {
if (m_overlappingPoints.find(idx) != m_overlappingPoints.end()) {
//Add to mask
allPointsMask.at<uchar>(j, i) = 255;
}
else {
for (auto pObjEntity : objEntities) {
if (m_pInstanceSeg[idx] == pObjEntity->entityID) {
allPointsMask.at<uchar>(j, i) = 255;
break;
}
}
}
}
}
}
//Test by printing out image
/*{
std::string entitiesStr;
for (auto pObjEntity : objEntities) {
entitiesStr.append(std::to_string(pObjEntity->entityID));
entitiesStr.append("-");
}
entitiesStr.append("allPointsMask");
std::string filename = getStandardFilename(entitiesStr, ".png");
cv::imwrite(filename, allPointsMask);
}*/
//Create individual segmented masks
int floodVal = 1;
for (int j = 0; j < s_camParams.height; ++j) {
for (int i = 0; i < s_camParams.width; ++i) {
if (allPointsMask.at<uchar>(j, i) == 255) {
cv::floodFill(allPointsMask, cv::Point(i,j), cv::Scalar(floodVal));
++floodVal;
}
}
}
//Test by printing out image
/*{
std::string entitiesStr;
for (auto pObjEntity : objEntities) {
entitiesStr.append(std::to_string(pObjEntity->entityID));
entitiesStr.append("-");
}
entitiesStr.append("floodFilledMask");
std::string filename = getStandardFilename(entitiesStr, ".png");
cv::imwrite(filename, allPointsMask);
}*/
//Check if each floodFill value only has singular points from one entity
std::vector<int> floodFillEntities(floodVal - 1, 0);
std::vector<bool> goodFloods(floodVal - 1, true);
for (int j = 0; j < s_camParams.height; ++j) {
for (int i = 0; i < s_camParams.width; ++i) {
int curFloodVal = allPointsMask.at<uchar>(j, i);
if (curFloodVal != 0) {
int idx = j * s_camParams.width + i;
int entityID = m_pInstanceSeg[idx];
if (entityID != 0) {
int floodEntityID = floodFillEntities[curFloodVal - 1];
if (floodEntityID == 0) floodFillEntities[curFloodVal - 1] = entityID;
else if (entityID == floodEntityID) continue;
else goodFloods[curFloodVal - 1] = false;
}
}
}
}
//If yes, set all points in that segment mask to the corresponding entity
for (int j = 0; j < s_camParams.height; ++j) {
for (int i = 0; i < s_camParams.width; ++i) {
int curFloodVal = allPointsMask.at<uchar>(j, i);
if (curFloodVal != 0 && m_pInstanceSeg[j * s_camParams.width + i] == 0) {
if (goodFloods[curFloodVal - 1]) {
for (ObjEntity* objEnt : objEntities) {
if (objEnt->entityID == floodFillEntities[curFloodVal - 1]) {
addSegmentedPoint3D(i, j, objEnt);
//Also zero the mask pixel so we don't use it in the future
allPointsMask.at<uchar>(j, i) = 0;
break;
}
}
}
else {
int idx = j * s_camParams.width + i;
//Last resort just set the point to be the entity of the nearest 3D point
float dist = FLT_MAX;
ObjEntity* closestObj = NULL;
float ndc = m_pDepth[idx];
Vector3 relPos = depthToCamCoords(ndc, i, j);
for (auto pObjEntity : objEntities) {
float distToObj = sqrt(SYSTEM::VDIST2(pObjEntity->location.x, pObjEntity->location.y, pObjEntity->location.z, relPos.x, relPos.y, relPos.z));
if (distToObj < dist) {
dist = distToObj;
closestObj = pObjEntity;
}
}
addSegmentedPoint3D(i, j, closestObj);
}
}
}
}
//For testing print out indices which can't separate with flood fill so they can be visually inspected
for (int i = 0; i < floodVal; ++i) {
if (goodFloods[i] == false) {
std::ostringstream oss2;
oss2 << "**************Found bad flood at index: " << instance_index << " with floodval: " <<floodVal << " and i: " << i;
std::string str = oss2.str();
log(str, true);
}
}
//Round 2: If a segment from above has more than two sure entities in it
//Then try creating contours within this mask from the depth threshold
//Separate then check if new segments only have one sure entity in them
//Create an image with the depth values only where the mask is
//Initialize depth mask
//cv::Mat depthMasked;
//m_depthMat.copyTo(depthMasked, allPointsMask);
//depthMasked *= FLT_MAX / s_camParams.farClip;
////Test by printing out image
//{
// std::string entitiesStr;
// for (auto pObjEntity : objEntities) {
// entitiesStr.append(std::to_string(pObjEntity->entityID));
// entitiesStr.append("-");
// }
// entitiesStr.append("depthMasked");
// std::string filename = getStandardFilename(entitiesStr, ".png");
// cv::imwrite(filename, depthMasked);
//}
std::ostringstream oss2;
oss2 << "Overlapping points size: " << m_overlappingPoints.size();
std::string str = oss2.str();
log(str, true);
//If point is still in overlapping points then remove it
if (m_overlappingPoints.find(ptIdx) != m_overlappingPoints.end()) {
m_overlappingPoints.erase(ptIdx);
}
allPointsMask.release();
}
//Reset the map once done processing
m_overlappingPoints.clear();
}
std::vector<ObjEntity*> ObjectDetection::pointInside3DEntities(const Vector3 &worldPos, EntityMap* eMap, const bool &checkUpperVehicle, const uint8_t &stencilVal) {
//Get vector of entities which point resides in their 3D box
std::vector<ObjEntity*> pointEntities;
for (auto &entry : *eMap) {
ObjEntity* e = &(entry.second);
bool upperHalf;
bool isIn3DBox = in3DBox(e, worldPos, upperHalf);
if (isIn3DBox) {
//Add only pedestrian stencil types to pedestrian 3D bboxes
//Add any points which are vehicle stencil type or
//are in the upper half of the vehicle's 3D bounding box
//This allows window points to be added for vehicles
if (!checkUpperVehicle || stencilVal == STENCIL_TYPE_VEHICLE || upperHalf) {
pointEntities.push_back(e);
}
}
}
return pointEntities;
}
//j is y coordinate (top=0), i is x coordinate (left = 0)
void ObjectDetection::processStencilPixel3D(const uint8_t &stencilVal, const int &j, const int &i,
const Vector3 &xVectorCam, const Vector3 &yVectorCam, const Vector3 &zVectorCam) {
float ndc = m_pDepth[j * s_camParams.width + i];
Vector3 relPos = depthToCamCoords(ndc, i, j);
Vector3 worldPos = convertCoordinateSystem(relPos, yVectorCam, xVectorCam, zVectorCam);
worldPos.x += s_camParams.pos.x;
worldPos.y += s_camParams.pos.y;
worldPos.z += s_camParams.pos.z;
//Obtain proper map for stencil type
//Need to check all points for vehicles since depth map hits windows but
//stencil buffer hits entities through windows
EntityMap* eMap;
bool checkUpperVehicle = false;
if (stencilVal == STENCIL_TYPE_NPC) {
eMap = &m_curFrame.peds;
}
else {
eMap = &m_curFrame.vehicles;
checkUpperVehicle = true;
}
//Check 2D boxes first for vehicle and pedestrian stencil pixels
//Stencil goes through vehicle windows but depth buffer does not
std::vector<ObjEntity*> pointEntities2D;
if (stencilVal == STENCIL_TYPE_NPC || stencilVal == STENCIL_TYPE_VEHICLE) {
for (auto &entry : *eMap) {
ObjEntity* e = &(entry.second);
if (in2DBoxUnprocessed(i, j, e)) {
pointEntities2D.push_back(e);
}
}
//If point only lies in one 2D bounding box then accept this entity as the true entity
if (pointEntities2D.size() == 1) {
addSegmentedPoint3D(i, j, pointEntities2D[0]);
return;
}
}
std::vector<ObjEntity*> pointEntities = pointInside3DEntities(worldPos, eMap, checkUpperVehicle, stencilVal);
//All vehicle points should fall within a vehicle 3D bounding box
//Pedestrians in vehicles may not since the windows are what the depth model hits
//Try setting the pedestrian stencil type to a vehicle and checking again if this is the case
if (pointEntities.empty() && stencilVal == STENCIL_TYPE_NPC) {
eMap = &m_curFrame.vehicles;
checkUpperVehicle = true;
pointEntities = pointInside3DEntities(worldPos, eMap, checkUpperVehicle, STENCIL_TYPE_VEHICLE);
}
//3 choices, no, single, or multiple 3D box matches
if (pointEntities.empty()) {
//Should never hit here, point will not get added for outlier cases
}
else if (pointEntities.size() == 1) {
addSegmentedPoint3D(i, j, pointEntities[0]);
}
else {
//If the overlapping entities are all peds in the same vehicle
//simply add it as it will just be set to the vehicle
if (stencilVal == STENCIL_TYPE_NPC && pointEntities[0]->isPedInV) {
int vEntityID = pointEntities[0]->vPedIsIn;
bool allSameV = true;
for (int i = 1; i < pointEntities.size(); ++i) {
if (!pointEntities[i]->isPedInV || pointEntities[i]->vPedIsIn != pointEntities[0]->vPedIsIn) {
allSameV = false;
break;
}
}
if (allSameV) {
addSegmentedPoint3D(i, j, pointEntities[0]);
return;
}
}
//Index of point
int idx = j * s_camParams.width + i;
//Map should only hit each idx once, so no need for alternative if idx is found
if (PROCESS_OVERLAPPING_POINTS) {
if (m_overlappingPoints.find(idx) == m_overlappingPoints.end()) {
m_overlappingPoints.insert(std::pair<int, std::vector<ObjEntity*>>(idx, pointEntities));
}
else {
log("************************This should never be here!!!!!!!!!!!!!!!!!!!", true);
}
}