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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AR_Sandbox
ar_sandbox_lib
Commits
13e28b91
Commit
13e28b91
authored
5 years ago
by
simon.fanetti
Browse files
Options
Downloads
Patches
Plain Diff
fixe usage + start adapting Controller to the new architecture
parent
da9daa3b
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
includes/controller.h
+3
-11
3 additions, 11 deletions
includes/controller.h
src/core/components/calibrate.cpp
+5
-4
5 additions, 4 deletions
src/core/components/calibrate.cpp
src/core/controller.cpp
+59
-188
59 additions, 188 deletions
src/core/controller.cpp
src/sandbox.cpp
+1
-1
1 addition, 1 deletion
src/sandbox.cpp
with
68 additions
and
204 deletions
includes/controller.h
+
3
−
11
View file @
13e28b91
...
...
@@ -15,17 +15,13 @@ class Controller
cv
::
Mat
getRGBFrame
();
cv
::
Mat
getDepthFrame
();
void
showImage
(
cv
::
Mat
*
image
);
//void exportToAsc(cv::Mat frame, char *fileName);
//void exportFrame(cv::Mat src, char *fileName);
//bool importFrame(char *fileName, cv::Mat &output);
void
setupConfig
();
private:
const
char
*
SANDBOX_POSITION_FILE
=
"./sandbox.dat"
;
const
char
*
CALIBRATE_DISTANCE_FILE
=
"./distance.dat"
;
const
char
*
CALIBRATE_MATRIX_FILE
=
"./matrixe.dat"
;
static
const
char
CHAR_DELIM
=
' '
;
//const float SANDBOX_CONTOUR = 2.0f * (1020.0f + 770.0f);
//const float MARGE = 0.05 * SANDBOX_CONTOUR; // 5% of marge
static
const
int
ESCAPE_CHAR
=
27
;
char
*
defaultWindowsName
=
(
char
*
)
"Image"
;
cv
::
Rect
rectSandbox
;
...
...
@@ -34,13 +30,9 @@ class Controller
Beamer
beamer
;
void
createWindowsFullScreen
(
char
*
windowName
);
void
showImage
(
cv
::
Mat
*
image
,
char
*
windowName
);
//bool readSandboxPosition(std::vector<cv::Point> &rectPoints);
//void writeSandboxPosition(std::vector<cv::Point> rectPoints);
double
toDegrees
(
double
radians
);
void
sanboxBorder
();
//void sandboxBorderLoad();
//bool configFilesFound();
void
setupProjection
(
Camera
*
camera
);
void
setupBeamerLocation
(
Beamer
*
beamer
,
Camera
*
camera
);
};
...
...
This diff is collapsed.
Click to expand it.
src/core/components/calibrate.cpp
+
5
−
4
View file @
13e28b91
...
...
@@ -6,6 +6,7 @@ using namespace std;
Calibrate
::
Calibrate
()
{
matRotation
=
getRotationMatrix2D
(
Point
(
0
,
0
),
0
,
1
);
}
Point2i
Calibrate
::
rotatePixel
(
Point2i
pixel
)
...
...
@@ -32,7 +33,7 @@ Point2i Calibrate::transformationPixel(int i, int j, float z, Camera camera, Poi
void
Calibrate
::
transformationFrame
(
cv
::
Mat
&
src
,
cv
::
Mat
&
dst
,
Camera
camera
,
Point3f
beamer
)
{
int64_t
t1
=
getTickCount
();
//
int64_t t1 = getTickCount();
//transformation on all pixel
for
(
int
i
=
0
;
i
<
src
.
rows
;
i
++
)
{
...
...
@@ -44,7 +45,7 @@ void Calibrate::transformationFrame(cv::Mat &src, cv::Mat &dst, Camera camera, P
dst
.
at
<
uint16_t
>
(
pixel
)
=
src
.
at
<
uint16_t
>
(
pixelIJ
);
}
}
cout
<<
"temps de calcul: "
<<
(
getTickCount
()
-
t1
)
/
getTickFrequency
()
<<
endl
;
//
cout << "temps de calcul: " << (getTickCount() - t1) / getTickFrequency() << endl;
warpAffine
(
dst
,
dst
,
matRotation
,
dst
.
size
());
// medianBlur(dst, dst, 3);
...
...
@@ -54,7 +55,7 @@ void Calibrate::transformationFrame(cv::Mat &depth, cv::Mat &src, cv::Mat &dst,
{
int
nbChannel
=
src
.
channels
();
//transformation on all pixel
int64_t
t1
=
getTickCount
();
//
int64_t t1 = getTickCount();
for
(
int
i
=
0
;
i
<
src
.
rows
;
i
++
)
{
for
(
int
j
=
0
;
j
<
src
.
cols
;
j
++
)
...
...
@@ -70,7 +71,7 @@ void Calibrate::transformationFrame(cv::Mat &depth, cv::Mat &src, cv::Mat &dst,
}
}
}
cout
<<
"temps de calcul: "
<<
(
getTickCount
()
-
t1
)
/
getTickFrequency
()
<<
endl
;
//
cout << "temps de calcul: " << (getTickCount() - t1) / getTickFrequency() << endl;
warpAffine
(
dst
,
dst
,
matRotation
,
dst
.
size
());
dilate
(
dst
,
dst
,
Mat
(),
Point
(
-
1
,
-
1
),
2
,
1
,
1
);
erode
(
dst
,
dst
,
Mat
(),
Point
(
-
1
,
-
1
),
2
,
1
,
1
);
...
...
This diff is collapsed.
Click to expand it.
src/core/controller.cpp
+
59
−
188
View file @
13e28b91
...
...
@@ -6,22 +6,20 @@
using
namespace
std
;
using
namespace
cv
;
/*
* MAIN
*/
Controller
::
Controller
(){
bool
configSanbox
=
true
;
//cout << "All files there? " << configFilesFound() << endl;
if
(
configSanbox
){
// Blue screen and edit colored frame routine
sanboxBorder
();
// Matching cross under beamer routine
beamer
.
findBeamer
(
camera
);
}
else
{
//sandboxBorderLoad();
//beamer.findBeamerLoad(camera);
}
// Set full screen parameter for show function
createWindowsFullScreen
(
defaultWindowsName
);
}
/*
* PUBLIC
*/
Mat
Controller
::
getRGBFrame
(){
camera
.
captureFramesAlign
();
return
camera
.
getRGBFrameAlign
()(
rectSandbox
);
...
...
@@ -36,6 +34,34 @@ void Controller::showImage(cv::Mat* image){
showImage
(
image
,
defaultWindowsName
);
}
void
Controller
::
setupConfig
(){
// Blue screen and edit colored frame routine
setupProjection
(
&
camera
);
// Matching cross under beamer routine
setupBeamerLocation
(
&
beamer
,
&
camera
);
createWindowsFullScreen
(
defaultWindowsName
);
// Debug
Mat
matRotation
=
calibrate
.
getMatrixRotation
();
cout
<<
"Adjusting Matrix"
<<
endl
;
for
(
int
y
=
0
;
y
<
matRotation
.
rows
;
y
++
){
for
(
int
x
=
0
;
x
<
matRotation
.
cols
;
x
++
){
cout
<<
matRotation
.
at
<
float
>
(
y
,
x
)
<<
" "
;
}
cout
<<
endl
;
}
cout
<<
"Cropping Mask (base + size)"
<<
endl
;
cout
<<
"("
<<
rectSandbox
.
x
<<
","
<<
rectSandbox
.
y
<<
") + "
;
cout
<<
"("
<<
rectSandbox
.
width
<<
","
<<
rectSandbox
.
height
<<
")"
<<
endl
;
}
/*
* PRIVATE
*/
void
Controller
::
showImage
(
cv
::
Mat
*
image
,
char
*
windowName
){
static
Mat
frameBeamer
(
Size
(
Beamer
::
width
,
Beamer
::
height
),
CV_8UC3
);
camera
.
captureFramesAlign
();
...
...
@@ -54,209 +80,54 @@ double Controller::toDegrees(double radians){
return
radians
*
(
180.0
/
M_PI
);
}
/*
bool Sandbox::readSandboxPosition(vector<Point> &rectPoints)
{
std::ifstream infile(SANDBOX_POSITION_FILE);
if (infile.good())
{
int x, y;
while (infile >> x >> y)
{
rectPoints.push_back(Point(x, y));
cout << x << " " << y << endl;
}
}
infile.close();
return rectPoints.size() == 4;
}
void Sandbox::writeSandboxPosition(vector<Point> rectPoints)
{
//export points to file
std::ofstream myfile;
myfile.open(SANDBOX_POSITION_FILE);
for (unsigned int i = 0; i < rectPoints.size(); i++)
myfile << rectPoints[i].x << " " << rectPoints[i].y << endl;
myfile.close();
}*/
/*
void Sandbox::sandboxBorderLoad(){
float distancePlan;
Mat matRotation;
// Distance Plan
std::ifstream infile(CALIBRATE_DISTANCE_FILE);
if (infile.good()){
while (infile >> distancePlan){
cout << distancePlan << endl;
}
}
infile.close();
// Matrix Rotation
char *filename = "";
strcpy(filename, CALIBRATE_MATRIX_FILE);
importFrame(filename, matRotation);
calibrate.setDistancePlan(distancePlan);
}
void Sandbox::exportToAsc(Mat src, char *fileName)
{
std::ofstream myfile;
myfile.open(fileName);
Mat frameSand = src(rectSandbox);
for (int y = 0; y < src.rows; y++)
{
for (int x = 0; x < src.cols; x++)
{
myfile << x << " " << y << " " << frameSand.at<uint16_t>(y, x) << "\n";
}
}
myfile.close();
void
Controller
::
createWindowsFullScreen
(
char
*
windowName
){
namedWindow
(
windowName
,
CV_WINDOW_NORMAL
);
setWindowProperty
(
windowName
,
CV_WND_PROP_FULLSCREEN
,
CV_WINDOW_FULLSCREEN
);
}
void Sandbox::exportFrame(Mat src, char *fileName)
{
std::ofstream myfile;
myfile.open(fileName);
Mat frameSand = src(rectSandbox);
myfile << frameSand.cols << " " << frameSand.rows << endl;
for (int y = 0; y < frameSand.rows; y++)
{
for (int x = 0; x < frameSand.cols; x++)
{
myfile << frameSand.at<uint16_t>(y, x) << CHAR_DELIM;
}
myfile << endl;
}
myfile.close();
}
bool Sandbox::importFrame(char *fileName, Mat &output)
{
std::ifstream file(fileName);
if (file.is_open())
{
string elem;
int i = 0;
//read header
getline(file, elem, CHAR_DELIM);
int width = atoi(elem.c_str());
getline(file, elem, CHAR_DELIM);
int height = atoi(elem.c_str());
//create & read matrix
output = Mat(Size(width, height), CV_16UC1);
cout << width << " " << height << endl;
while (getline(file, elem, CHAR_DELIM))
{
output.at<uint16_t>(i / width, i % width) = (uint16_t)atoi(elem.c_str());
i++;
}
file.close();
return true;
}
return false;
}
bool Sandbox::configFilesFound(){
const char* files[] = { SANDBOX_POSITION_FILE,
CALIBRATE_DISTANCE_FILE,
CALIBRATE_MATRIX_FILE };
int size = (sizeof(files)/sizeof(char*));
for (int i = 0; i < size; i++)
{
char *filename = "";
strcpy(filename, files[i]);
std::ifstream infile(filename);
if(infile.fail()){
cout << "Configuration file missing...";
return false;
}
void
Controller
::
setupBeamerLocation
(
Beamer
*
beamer
,
Camera
*
camera
){
beamer
->
findBeamer
(
*
camera
);
}
return true;
}*/
void
Controller
::
setupProjection
(
Camera
*
camera
){
void
Controller
::
sanboxBorder
()
{
// Blue screen
char
windowName
[]
=
"border"
;
createWindowsFullScreen
(
windowName
);
Mat
frameBeamer
(
Size
(
Beamer
::
width
,
Beamer
::
height
),
CV_8UC3
,
Scalar
(
255
,
0
,
0
));
// Show blue frame
imshow
(
windowName
,
frameBeamer
);
waitKey
(
100
);
camera
.
startAlign
();
// 1 seconde of warming up
camera
.
captureFramesAlign
();
Mat
frameData
=
camera
.
getDepthFrameAlign
();
Mat
coloredFrame
=
camera
.
getRGBFrameAlign
();
// Take picture
camera
->
startAlign
();
// 1 seconde of warming up
camera
->
captureFramesAlign
();
Mat
frameData
=
camera
->
getDepthFrameAlign
();
Mat
coloredFrame
=
camera
->
getRGBFrameAlign
();
Size
s
=
frameData
.
size
();
Point
center
(
s
.
width
/
2
,
s
.
height
/
2
);
// calibrate distance
//Point center(s.width / 2, s.height / 2);
//float distancePlan = static_cast<float>(mean(frameData(Rect(center, Size(10, 10))))[0]); // get sandbox distance from center of camera
//calibrate.setDistancePlan(distancePlan);
destroyAllWindows
();
vector
<
Point
>
rectPoints
;
// Edit projection
float
y
=
coloredFrame
.
size
().
height
;
float
x
=
coloredFrame
.
size
().
width
;
rectPoints
.
push_back
(
Point
(
1.0
/
4
*
x
,
1.0
/
4
*
y
));
rectPoints
.
push_back
(
Point
(
1.0
/
4
*
x
,
3.0
/
4
*
y
));
rectPoints
.
push_back
(
Point
(
3.0
/
4
*
x
,
3.0
/
4
*
y
));
rectPoints
.
push_back
(
Point
(
3.0
/
4
*
x
,
1.0
/
4
*
y
));
vector
<
Point
>
rectPoints
{
Point
(
1.0
/
4
*
x
,
1.0
/
4
*
y
),
Point
(
1.0
/
4
*
x
,
3.0
/
4
*
y
),
Point
(
3.0
/
4
*
x
,
3.0
/
4
*
y
),
Point
(
3.0
/
4
*
x
,
1.0
/
4
*
y
)
};
cout
<<
"Edit Rectangle"
<<
endl
;
BorderEdit
::
edit
(
coloredFrame
,
&
rectPoints
);
// edit projected frame
// adjust
model
matrix
e to forme a rectangle in sandbox
//
Set
adjust
ing
matrix
for the projection
int
widthTop
=
rectPoints
[
3
].
x
-
rectPoints
[
0
].
x
;
double
angle1
=
atan
((
double
)(
rectPoints
[
3
].
y
-
rectPoints
[
0
].
y
)
/
widthTop
);
Mat
matRotation
=
getRotationMatrix2D
(
center
,
toDegrees
(
angle1
),
1
);
calibrate
.
setMatrixRotation
(
matRotation
);
cout
<<
"Calibrate Rotation Matrixe"
<<
endl
;
Mat
matRotation
=
getRotationMatrix2D
(
center
,
toDegrees
(
angle1
),
1
);
// adjustingMatrix
calibrate
.
setMatrixRotation
(
matRotation
);
// Set cropping mask
Size
rectSize
=
Size
(
widthTop
,
cvRound
(
widthTop
/
1.33333
)
+
5
);
Point
p
=
calibrate
.
rotatePixel
(
rectPoints
[
0
]);
// rectSandbox => CroppingMask
rectSandbox
=
Rect
(
p
,
rectSize
);
//writeSandboxPosition(rectPoints); // update with adjusted sandbox's angles
rectSandbox
=
Rect
(
p
,
rectSize
);
// coppingMask
destroyAllWindows
();
/*
TODO : save matRotation in config_file
*/
/*cout << "Saving matrixe in file..." << endl;
myfile.open(CALIBRATE_MATRIX_FILE);
cout << "Data : " << matRotation.rows << " : " << matRotation.cols << endl;
myfile << matRotation.cols << " " << matRotation.rows << endl;
for (int y = 0; y < matRotation.rows; y++)
{
for (int x = 0; x < matRotation.cols; x++)
{
myfile << matRotation.at<uint16_t>(y, x) << CHAR_DELIM;
}
myfile << endl;
}
myfile.close();
cout << "Done..." << endl;*/
}
void
Controller
::
createWindowsFullScreen
(
char
*
windowName
)
{
namedWindow
(
windowName
,
CV_WINDOW_NORMAL
);
setWindowProperty
(
windowName
,
CV_WND_PROP_FULLSCREEN
,
CV_WINDOW_FULLSCREEN
);
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/sandbox.cpp
+
1
−
1
View file @
13e28b91
#include
"../includes/sandbox.h"
Sandbox
::
Sandbox
(){
controller
=
Controller
();
controller
.
setupConfig
();
}
cv
::
Mat
Sandbox
::
getRGBFrame
(){
...
...
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