Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ar_sandbox_lib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AR_Sandbox
ar_sandbox_lib
Commits
df8b4975
Commit
df8b4975
authored
4 years ago
by
simon.fanetti
Browse files
Options
Downloads
Patches
Plain Diff
idea to manipulate matrixes without for loops
parent
f2124872
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
inc/camera.h
+4
-0
4 additions, 0 deletions
inc/camera.h
inc/projection.h
+4
-1
4 additions, 1 deletion
inc/projection.h
src/components/camera.cpp
+58
-0
58 additions, 0 deletions
src/components/camera.cpp
src/components/projection.cpp
+73
-11
73 additions, 11 deletions
src/components/projection.cpp
with
139 additions
and
12 deletions
inc/camera.h
+
4
−
0
View file @
df8b4975
...
...
@@ -42,6 +42,10 @@ class Camera{
void
stop
();
cv
::
Point3f
deprojectPixelToPoint
(
float
coord
[],
float
z1
);
cv
::
Point2i
projectPointToPixel
(
cv
::
Point3f
point3D
);
void
deprojectPixelToPoint
(
cv
::
Mat_
<
float
>
&
depth
,
cv
::
Mat_
<
cv
::
Point3f
>
&
real
);
void
projectPointToPixel
(
cv
::
Mat_
<
cv
::
Point3f
>
&
real
,
cv
::
Mat_
<
cv
::
Point2i
>
&
pixels
);
void
capture
();
void
printCroppingMask
();
...
...
This diff is collapsed.
Click to expand it.
inc/projection.h
+
4
−
1
View file @
df8b4975
...
...
@@ -13,9 +13,11 @@ class Projection{
void
deprojectPixelsFromDepth
(
cv
::
Mat_
<
float
>
&
depth
,
cv
::
Rect
mask
,
Camera
*
camera
,
cv
::
Point3f
beamer_pos
,
cv
::
Mat_
<
cv
::
Point2i
>
&
deprojectMap
);
void
filterLowestDeprojectedPoints
(
cv
::
Mat_
<
float
>
&
depth
,
cv
::
Mat_
<
cv
::
Point2i
>
&
deprojectMap
,
cv
::
Mat_
<
cv
::
Point2i
>
&
frameMapMask
);
void
buildFrame
(
cv
::
Mat_
<
float
>
&
depth
,
cv
::
Mat_
<
cv
::
Point2i
>
&
frameMapMask
,
cv
::
Mat_
<
cv
::
Vec3b
>
&
src
,
cv
::
Mat_
<
cv
::
Vec3b
>
&
dst
);
void
buildFrame2
(
cv
::
Mat_
<
cv
::
Point2i
>
&
frameMapMask
,
cv
::
Mat_
<
cv
::
Vec3b
>
&
src
,
cv
::
Mat_
<
cv
::
Vec3b
>
&
dst
);
cv
::
Point2i
findMatchingPixel
(
int
i
,
int
j
,
float
z
,
Camera
*
camera
,
cv
::
Point3f
beamer_pos
);
void
copyPixelsInto
(
cv
::
Point2i
pixel_dst
,
cv
::
Mat_
<
cv
::
Vec3b
>
&
dst
,
cv
::
Point2i
pixel_src
,
cv
::
Mat_
<
cv
::
Vec3b
>
&
src
,
cv
::
Mat_
<
float
>
&
depth
);
cv
::
Size
getMatchingSize
(
cv
::
Mat_
<
cv
::
Vec3b
>
&
src
,
cv
::
Rect
base
);
cv
::
Size
getMatchingSize
(
cv
::
Mat
&
src
,
cv
::
Mat
&
base
);
public:
Projection
();
...
...
@@ -28,6 +30,7 @@ class Projection{
cv
::
Point2i
rotatePixel
(
cv
::
Point2i
pixel
);
cv
::
Point2i
revertRotatePixel
(
cv
::
Point2i
pixel
);
void
adjustFrame
(
cv
::
Mat_
<
float
>
depth
,
cv
::
Mat_
<
cv
::
Vec3b
>
src
,
cv
::
Mat_
<
cv
::
Vec3b
>
&
dst
,
Camera
*
camera
,
cv
::
Point3f
beamer_pos
);
void
adjustFrame2
(
cv
::
Mat_
<
float
>
depth
,
cv
::
Mat_
<
cv
::
Vec3b
>
src
,
cv
::
Mat_
<
cv
::
Vec3b
>
&
dst
,
Camera
*
camera
,
cv
::
Point3f
beamer_pos
);
void
printAdjustingMatrix
();
};
...
...
This diff is collapsed.
Click to expand it.
src/components/camera.cpp
+
58
−
0
View file @
df8b4975
...
...
@@ -114,6 +114,64 @@ cv::Point3f Camera::deprojectPixelToPoint(float coord[], float z){
}
void
Camera
::
deprojectPixelToPoint
(
cv
::
Mat_
<
float
>
&
depth
,
cv
::
Mat_
<
cv
::
Point3f
>
&
real
){
/*
// RS2_DISTORTION_BROWN_CONRADY
float x = (pixel[0] - intrin->ppx) / intrin->fx;
float y = (pixel[1] - intrin->ppy) / intrin->fy;
point[0] = depth * x;
point[1] = depth * y;
point[2] = depth;
*/
float
ppx
=
intr_profile
.
ppx
*
depth
.
size
().
width
/
intr_profile
.
width
;
float
ppy
=
intr_profile
.
ppy
*
depth
.
size
().
height
/
intr_profile
.
height
;
float
fx
=
depth
.
size
().
width
*
intr_profile
.
fx
/
intr_profile
.
width
;
float
fy
=
depth
.
size
().
height
*
intr_profile
.
fy
/
intr_profile
.
height
;
for
(
int
j
=
0
;
j
<
depth
.
rows
;
j
++
){
for
(
int
i
=
0
;
i
<
depth
.
cols
;
i
++
){
float
x
=
(
i
-
ppx
)
/
fx
;
float
y
=
(
j
-
ppy
)
/
fy
;
float
depth_ij
=
depth
.
at
<
float
>
(
j
,
i
);
real
.
at
<
cv
::
Point3f
>
(
j
,
i
)
=
cv
::
Point3f
(
depth_ij
*
x
,
depth_ij
*
y
,
depth_ij
);
}
}
}
void
Camera
::
projectPointToPixel
(
cv
::
Mat_
<
cv
::
Point3f
>
&
real
,
cv
::
Mat_
<
cv
::
Point2i
>
&
pixels
){
/*
// RS2_DISTORTION_BROWN_CONRADY
float x = point[0] / point[2], y = point[1] / point[2];
pixel[0] = x * intrin->fx + intrin->ppx;
pixel[1] = y * intrin->fy + intrin->ppy;
*/
float
ppx
=
intr_profile
.
ppx
*
real
.
size
().
width
/
intr_profile
.
width
;
float
ppy
=
intr_profile
.
ppy
*
real
.
size
().
height
/
intr_profile
.
height
;
float
fx
=
real
.
size
().
width
*
intr_profile
.
fx
/
intr_profile
.
width
;
float
fy
=
real
.
size
().
height
*
intr_profile
.
fy
/
intr_profile
.
height
;
for
(
int
j
=
0
;
j
<
pixels
.
rows
;
j
++
){
for
(
int
i
=
0
;
i
<
pixels
.
cols
;
i
++
){
cv
::
Point3f
pt
=
real
.
at
<
cv
::
Point3f
>
(
j
,
i
);
float
x
=
pt
.
x
/
pt
.
z
;
float
y
=
pt
.
y
/
pt
.
z
;
pixels
.
at
<
cv
::
Point2i
>
(
j
,
i
)
=
cv
::
Point2i
(
x
*
fx
+
ppx
,
y
*
fy
+
ppy
);
}
}
}
void
Camera
::
printCroppingMask
(){
cv
::
Rect
mask
=
getCroppingMask
();
std
::
cout
<<
"("
<<
mask
.
x
<<
","
<<
mask
.
y
<<
") + "
<<
mask
.
width
<<
"x"
<<
mask
.
height
<<
std
::
endl
;
...
...
This diff is collapsed.
Click to expand it.
src/components/projection.cpp
+
73
−
11
View file @
df8b4975
...
...
@@ -31,21 +31,19 @@ cv::Point2i Projection::revertRotatePixel(cv::Point2i pixel){
// Adjust the projected frame with the topology from the camera to the beamer POV
void
Projection
::
adjustFrame
(
cv
::
Mat_
<
float
>
depth
,
cv
::
Mat_
<
cv
::
Vec3b
>
src
,
cv
::
Mat_
<
cv
::
Vec3b
>
&
dst
,
Camera
*
camera
,
cv
::
Point3f
beamer_pos
){
cv
::
Rect
mask
=
camera
->
getCroppingMask
();
// resize the frames to be a multiple of the camera size :
// src.size = n * camera.depth.size , where n is uint > 0
static
cv
::
Mat_
<
cv
::
Vec3b
>
resized_dst
=
cv
::
Mat_
<
cv
::
Vec3b
>
(
getMatchingSize
(
dst
,
mask
));
static
cv
::
Mat_
<
cv
::
Vec3b
>
resized_dst
=
cv
::
Mat_
<
cv
::
Vec3b
>
(
getMatchingSize
(
dst
,
depth
));
cv
::
resize
(
dst
,
resized_dst
,
resized_dst
.
size
());
cv
::
resize
(
src
,
src
,
resized_dst
.
size
());
static
cv
::
Mat_
<
cv
::
Point2i
>
deprojectMap
=
cv
::
Mat_
<
cv
::
Point2i
>
(
mask
.
height
,
mask
.
width
);
static
cv
::
Mat_
<
cv
::
Point2i
>
deprojectMap
=
cv
::
Mat_
<
cv
::
Point2i
>
(
depth
.
size
().
height
,
depth
.
size
()
.
width
);
deprojectMap
=
cv
::
Point2i
(
-
1
,
-
1
);
static
cv
::
Mat_
<
cv
::
Point2i
>
frameMapMask
=
cv
::
Mat_
<
cv
::
Point2i
>
(
mask
.
height
,
mask
.
width
,
cv
::
Point2i
(
-
1
,
-
1
));
static
cv
::
Mat_
<
cv
::
Point2i
>
frameMapMask
=
cv
::
Mat_
<
cv
::
Point2i
>
(
depth
.
size
().
height
,
depth
.
size
()
.
width
,
cv
::
Point2i
(
-
1
,
-
1
));
frameMapMask
=
cv
::
Point2i
(
-
1
,
-
1
);
deprojectPixelsFromDepth
(
depth
,
m
ask
,
camera
,
beamer_pos
,
deprojectMap
);
deprojectPixelsFromDepth
(
depth
,
camera
->
getCroppingM
ask
()
,
camera
,
beamer_pos
,
deprojectMap
);
filterLowestDeprojectedPoints
(
depth
,
deprojectMap
,
frameMapMask
);
...
...
@@ -57,6 +55,54 @@ void Projection::adjustFrame(cv::Mat_<float> depth, cv::Mat_<cv::Vec3b> src, cv:
cv
::
warpAffine
(
dst
,
dst
,
adjustingMatrix
,
dst
.
size
());
}
void
Projection
::
adjustFrame2
(
cv
::
Mat_
<
float
>
depth
,
cv
::
Mat_
<
cv
::
Vec3b
>
src
,
cv
::
Mat_
<
cv
::
Vec3b
>
&
dst
,
Camera
*
camera
,
cv
::
Point3f
beamer_pos
){
cv
::
resize
(
depth
,
depth
,
dst
.
size
());
cv
::
resize
(
src
,
src
,
dst
.
size
());
static
cv
::
Mat_
<
cv
::
Point2i
>
deprojectMap
=
cv
::
Mat_
<
cv
::
Point2i
>
(
depth
.
size
());
deprojectMap
=
cv
::
Point2i
(
-
1
,
-
1
);
static
cv
::
Mat_
<
cv
::
Point2i
>
frameMapMask
=
cv
::
Mat_
<
cv
::
Point2i
>
(
depth
.
size
(),
cv
::
Point2i
(
-
1
,
-
1
));
frameMapMask
=
cv
::
Point2i
(
-
1
,
-
1
);
cv
::
Point3f
CB
=
beamer_pos
;
static
cv
::
Mat_
<
cv
::
Point3f
>
CP
=
cv
::
Mat_
<
cv
::
Point3f
>
(
depth
.
size
());
static
cv
::
Mat_
<
cv
::
Point3f
>
BP
=
cv
::
Mat_
<
cv
::
Point3f
>
(
depth
.
size
());
static
cv
::
Mat_
<
cv
::
Point3f
>
BA
=
cv
::
Mat_
<
cv
::
Point3f
>
(
depth
.
size
());
static
cv
::
Mat_
<
cv
::
Point3f
>
BV
=
cv
::
Mat_
<
cv
::
Point3f
>
(
depth
.
size
());
static
cv
::
Mat_
<
cv
::
Point3f
>
CV
=
cv
::
Mat_
<
cv
::
Point3f
>
(
depth
.
size
());
static
cv
::
Mat_
<
float
>
alpha
=
cv
::
Mat_
<
float
>
(
depth
.
size
());
camera
->
deprojectPixelToPoint
(
depth
,
CP
);
/*
BP = CB;
BP -= CP;
BP *= -1;
BA = cv::Point3f(0,0,0);
BA.z = BP.z;
float BE = distanceTopSandbox - CB.z;
alpha = cv::norm(BA);
alpha /= BE;
BV = alpha * BP;
CV = CB + BV;
*/
camera
->
projectPointToPixel
(
CV
,
deprojectMap
);
filterLowestDeprojectedPoints
(
depth
,
deprojectMap
,
frameMapMask
);
buildFrame2
(
frameMapMask
,
src
,
dst
);
cv
::
warpAffine
(
dst
,
dst
,
adjustingMatrix
,
dst
.
size
());
}
/*
...
...
@@ -131,11 +177,27 @@ void Projection::buildFrame(cv::Mat_<float> &depth, cv::Mat_<cv::Point2i> &frame
}
}
void
Projection
::
buildFrame2
(
cv
::
Mat_
<
cv
::
Point2i
>
&
frameMapMask
,
cv
::
Mat_
<
cv
::
Vec3b
>
&
src
,
cv
::
Mat_
<
cv
::
Vec3b
>
&
dst
){
for
(
int
j
=
0
;
j
<
frameMapMask
.
rows
;
j
++
){
for
(
int
i
=
0
;
i
<
frameMapMask
.
cols
;
i
++
){
cv
::
Point2i
pixel_src
=
frameMapMask
.
at
<
cv
::
Point2i
>
(
j
,
i
);
cv
::
Point2i
pixel_dst
=
cv
::
Point2i
(
i
,
j
);
if
(
(
0
<=
pixel_src
.
x
&&
pixel_src
.
x
<
frameMapMask
.
cols
)
&&
(
0
<=
pixel_src
.
y
&&
pixel_src
.
y
<
frameMapMask
.
rows
)
){
// src and dst must be of same size
dst
.
at
<
cv
::
Vec3b
>
(
pixel_dst
)
=
src
.
at
<
cv
::
Vec3b
>
(
pixel_src
);
}
}
}
}
cv
::
Size
Projection
::
getMatchingSize
(
cv
::
Mat
_
<
cv
::
Vec3b
>
&
src
,
cv
::
Rec
t
base
){
cv
::
Size
Projection
::
getMatchingSize
(
cv
::
Mat
&
src
,
cv
::
Ma
t
&
base
){
cv
::
Size
bigSize
;
bigSize
.
width
=
(
src
.
size
().
width
%
base
.
width
==
0
)
?
src
.
size
().
width
:
src
.
size
().
width
-
(
src
.
size
().
width
%
base
.
width
)
+
base
.
width
;
bigSize
.
height
=
(
src
.
size
().
height
%
base
.
height
==
0
)
?
src
.
size
().
height
:
src
.
size
().
height
-
(
src
.
size
().
height
%
base
.
height
)
+
base
.
height
;
bigSize
.
width
=
(
src
.
size
().
width
%
base
.
size
().
width
==
0
)
?
src
.
size
().
width
:
src
.
size
().
width
-
(
src
.
size
().
width
%
base
.
size
().
width
)
+
base
.
size
().
width
;
bigSize
.
height
=
(
src
.
size
().
height
%
base
.
size
().
height
==
0
)
?
src
.
size
().
height
:
src
.
size
().
height
-
(
src
.
size
().
height
%
base
.
size
().
height
)
+
base
.
size
().
height
;
return
bigSize
;
}
...
...
@@ -178,8 +240,8 @@ cv::Point2i Projection::findMatchingPixel(int i, int j, float z, Camera *camera,
float
pixel
[
2
]
=
{
static_cast
<
float
>
(
i
),
static_cast
<
float
>
(
j
)};
cv
::
Point3f
CP
=
camera
->
deprojectPixelToPoint
(
pixel
,
z
);
cv
::
Point3f
BP
=
C
B
-
C
P
;
float
BAz
=
CB
.
z
+
BP
.
z
;
cv
::
Point3f
BP
=
C
P
-
C
B
;
float
BAz
=
BP
.
z
;
float
BEz
=
distanceTopSandbox
-
CB
.
z
;
float
alpha
=
BEz
/
BAz
;
cv
::
Point3f
V
=
(
alpha
*
BP
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment