Skip to content
Snippets Groups Projects
Commit 58a2b061 authored by Fabien Mottier's avatar Fabien Mottier
Browse files

process serialization working | need to check rotation matrice

parent a7b84832
No related branches found
No related tags found
No related merge requests found
...@@ -95,7 +95,7 @@ Beamer::~Beamer(){ ...@@ -95,7 +95,7 @@ Beamer::~Beamer(){
* \param rgb colored Frame * \param rgb colored Frame
* \return a vector for the detected circle (can be empty) * \return a vector for the detected circle (can be empty)
*/ */
vector<int> Beamer::findCercleZ(Mat &rgb) vector<Vec3f> Beamer::findCercleZ(Mat &rgb)
{ {
Mat src_gray; Mat src_gray;
cvtColor(rgb, src_gray, CV_BGR2GRAY); cvtColor(rgb, src_gray, CV_BGR2GRAY);
...@@ -108,7 +108,8 @@ vector<int> Beamer::findCercleZ(Mat &rgb) ...@@ -108,7 +108,8 @@ vector<int> Beamer::findCercleZ(Mat &rgb)
HoughCircles(src_gray, circles, CV_HOUGH_GRADIENT, 1, src_gray.rows / 4, 75, 50, 0, 0); HoughCircles(src_gray, circles, CV_HOUGH_GRADIENT, 1, src_gray.rows / 4, 75, 50, 0, 0);
//doit tester si le cercle est bon (rayon); //doit tester si le cercle est bon (rayon);
vector<int> result; return circles;
/*vector<int> result;
if (!circles.empty()) if (!circles.empty())
{ {
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
...@@ -116,7 +117,7 @@ vector<int> Beamer::findCercleZ(Mat &rgb) ...@@ -116,7 +117,7 @@ vector<int> Beamer::findCercleZ(Mat &rgb)
result.push_back(round(circles[0][i])); result.push_back(round(circles[0][i]));
} }
} }
return result; return result;*/
} }
/*! /*!
...@@ -125,15 +126,19 @@ vector<int> Beamer::findCercleZ(Mat &rgb) ...@@ -125,15 +126,19 @@ vector<int> Beamer::findCercleZ(Mat &rgb)
* \param i index of point to detect * \param i index of point to detect
* \return a tuple with the frame and the detected circle * \return a tuple with the frame and the detected circle
*/ */
tuple<Mat, vector<int>> Beamer::findPoint(Camera camera, int i) { tuple<Mat, vector<Vec3f>> Beamer::findPoint(Camera camera, int i) {
Mat rgb; Mat rgb;
Point p = points[i]; Point p = points[i];
camera.captureFramesAlign(); camera.captureFramesAlign();
rgb = camera.getRGBFrameAlign(); rgb = camera.getRGBFrameAlign();
Scalar color; Scalar color;
vector<int> crc = findCercleZ(rgb); vector<Vec3f> crc = findCercleZ(rgb);
if (!crc.empty())
for (int i = 0; i < crc.size(); ++i) {
circle(rgb, Point(round(crc[i][0]), round(crc[i][1])),round(crc[i][2]), Scalar(0,0,255), 4);
}
if (!crc.empty() && crc.size() == 1)
color = Scalar(0, 255, 0); color = Scalar(0, 255, 0);
else else
color = Scalar(0, 0, 255); color = Scalar(0, 0, 255);
...@@ -150,12 +155,12 @@ tuple<Mat, vector<int>> Beamer::findPoint(Camera camera, int i) { ...@@ -150,12 +155,12 @@ tuple<Mat, vector<int>> Beamer::findPoint(Camera camera, int i) {
* \param crc detected circle * \param crc detected circle
* Store the detect point * Store the detect point
*/ */
void Beamer::capturePoint(Camera camera, vector<int> crc) { void Beamer::capturePoint(Camera camera, vector<Vec3f> crc) {
Mat depth; Mat depth;
camera.captureFramesAlign(); camera.captureFramesAlign();
depth = camera.getDepthFrameAlign(); depth = camera.getDepthFrameAlign();
float coord[2] = {(float)crc[0], (float)crc[1]}; float coord[2] = {(float)crc[0][0], (float)crc[0][1]};
float z = static_cast<float>(depth.at<uint16_t>(crc[1], crc[0])); float z = static_cast<float>(depth.at<uint16_t>(crc[0][1], crc[0][0]));
Point3f p = camera.deprojectPixelToPoint(coord, z / 1000.0); Point3f p = camera.deprojectPixelToPoint(coord, z / 1000.0);
capturedPoints.push_back(p); capturedPoints.push_back(p);
} }
......
...@@ -12,7 +12,7 @@ class Beamer ...@@ -12,7 +12,7 @@ class Beamer
private: private:
float solveD(Vec3f v, Point3f p); float solveD(Vec3f v, Point3f p);
Point3f intersection(Vec3f v1, Point3f p1, Vec3f v2, Point3f p2, Vec3f v3, Point3f p3, bool &isFound); Point3f intersection(Vec3f v1, Point3f p1, Vec3f v2, Point3f p2, Vec3f v3, Point3f p3, bool &isFound);
vector<int> findCercleZ(Mat &rgb); vector<Vec3f> findCercleZ(Mat &rgb);
Point3f beamerPosition; Point3f beamerPosition;
vector<Point> points; vector<Point> points;
vector<Point3f> capturedPoints; vector<Point3f> capturedPoints;
...@@ -30,8 +30,8 @@ public: ...@@ -30,8 +30,8 @@ public:
beamerPosition = position; beamerPosition = position;
} }
void findBeamer(Camera camera); void findBeamer(Camera camera);
tuple<Mat, vector<int>> findPoint(Camera camera, int i); tuple<Mat, vector<Vec3f>> findPoint(Camera camera, int i);
void capturePoint(Camera camera, vector<int> crc); void capturePoint(Camera camera, vector<Vec3f> crc);
void findBeamerPosition(); void findBeamerPosition();
}; };
#endif #endif
...@@ -68,7 +68,7 @@ Mat Camera::captureFrame() ...@@ -68,7 +68,7 @@ Mat Camera::captureFrame()
} }
void Camera::captureFramesAlign() void Camera::captureFramesAlign()
{ {
rs2::align align(RS2_STREAM_DEPTH); rs2::align align(RS2_STREAM_COLOR);
auto frameset = pipe.wait_for_frames(); auto frameset = pipe.wait_for_frames();
//Get processed aligned frame //Get processed aligned frame
frameset = align.process(frameset); frameset = align.process(frameset);
......
...@@ -70,15 +70,25 @@ void Sandbox::serialize(ostream& stream) ...@@ -70,15 +70,25 @@ void Sandbox::serialize(ostream& stream)
Mat matRotation = calibrate.getMatrixRotation(); Mat matRotation = calibrate.getMatrixRotation();
int cols = matRotation.cols; int cols = matRotation.cols;
int rows = matRotation.rows; int rows = matRotation.rows;
int type = matRotation.type();
// Serialize beamer // Serialize beamer
int x, y, z; float x, y, z;
x = beamer.getPosition().x; x = beamer.getPosition().x;
y = beamer.getPosition().y; y = beamer.getPosition().y;
z = beamer.getPosition().z; z = beamer.getPosition().z;
// Seriliazation // Seriliazation
stream << serialnumber << "\t" << distance << "\t" << cols << "\t" << rows << "\t" << x << "\t" << y << "\t" << z << "\t"; stream << serialnumber << CHAR_DELIM << distance << CHAR_DELIM << x << CHAR_DELIM << y << CHAR_DELIM << z << CHAR_DELIM << cols << CHAR_DELIM << rows << CHAR_DELIM << type << CHAR_DELIM;
std::cout << rows << " | " << cols << endl;
for (int a = 0; a < matRotation.rows; a++)
{
for (int b = 0; b < matRotation.cols; b++)
{
std::cout << a << " | " << b << " : " << matRotation.at<uint16_t>(a, b) << endl;
stream << matRotation.at<uint16_t>(a, b) << CHAR_DELIM;
}
}
} }
/*! /*!
...@@ -90,19 +100,51 @@ void Sandbox::serialize(ostream& stream) ...@@ -90,19 +100,51 @@ void Sandbox::serialize(ostream& stream)
void Sandbox::deserialize(istream& stream) void Sandbox::deserialize(istream& stream)
{ {
// Deserialize the Intel RealSense Camera // Deserialize the Intel RealSense Camera
char* serialnumber; string serialnumber;
// Deserialize calibrate // Deserialize calibrate
float distancePlan; float distancePlan;
int cols, rows, type; int cols, rows, type;
Mat matRotation;
// Deserialize beamer // Deserialize beamer
int x, y, z; float x, y, z;
std::cout << "serialnumber" << endl;
// Deseriliazation // Deseriliazation
stream >> serialnumber >> distancePlan >> cols >> rows >> x >> y >> z;
stream >> serialnumber;
std::cout << "distancePlan" << endl;
stream >> distancePlan;
std::cout << "x" << endl;
stream >> x;
std::cout << "y" << endl;
stream >> y;
std::cout << "z" << endl;
stream >> z;
std::cout << "cols" << endl;
stream >> cols;
std::cout << "rows" << endl;
stream >> rows;
std::cout << "type" << endl;
stream >> type;
std::cout << "toto" << endl;
uint16_t* data[rows][cols];
for (int a = 0; a < rows; a++)
{
for (int b = 0; b < cols; b++)
{
uint16_t value;
stream >> value;
data[b][a];
std::cout << a << " | " << b << " : " << value << endl;
}
}
//Mat matRotation(rows, cols, type, data);
// Set Camera // Set Camera
int nbListRealSenseDevices = listRealSenseDevices.size(); int nbListRealSenseDevices = listRealSenseDevices.size();
...@@ -116,13 +158,14 @@ void Sandbox::deserialize(istream& stream) ...@@ -116,13 +158,14 @@ void Sandbox::deserialize(istream& stream)
//Set calibraton //Set calibraton
calibrate.setDistancePlan(distancePlan); calibrate.setDistancePlan(distancePlan);
calibrate.setMatrixRotation(matRotation); //calibrate.setMatrixRotation(matRotation);
// Set beamer // Set beamer
Point3f beamPosition(x, y, z); Point3f beamerPosition = Point3f(x, y, z);
beamer.setPosition(beamPosition); beamer.setPosition(beamerPosition);
} }
/*! /*!
* \brief Sandbox::generateBorder * \brief Sandbox::generateBorder
* \return the colored frame with a rectangle to place the border * \return the colored frame with a rectangle to place the border
...@@ -210,7 +253,7 @@ void Sandbox::applyBorder() { ...@@ -210,7 +253,7 @@ void Sandbox::applyBorder() {
* \return a tuple, with the frame and a vector to detect circle * \return a tuple, with the frame and a vector to detect circle
* Detect point with the circle to detect beamer * Detect point with the circle to detect beamer
*/ */
tuple<Mat, vector<int>> Sandbox::detectPointToDetectBeamer(int indexPoint) { tuple<Mat, vector<Vec3f>> Sandbox::detectPointToDetectBeamer(int indexPoint) {
return beamer.findPoint(camera, indexPoint); return beamer.findPoint(camera, indexPoint);
} }
...@@ -218,7 +261,7 @@ tuple<Mat, vector<int>> Sandbox::detectPointToDetectBeamer(int indexPoint) { ...@@ -218,7 +261,7 @@ tuple<Mat, vector<int>> Sandbox::detectPointToDetectBeamer(int indexPoint) {
* \brief Sandbox::capturePointToDetectBeamer * \brief Sandbox::capturePointToDetectBeamer
* \param crc circle vector * \param crc circle vector
*/ */
void Sandbox::capturePointToDetectBeamer(vector<int> crc) { void Sandbox::capturePointToDetectBeamer(vector<Vec3f> crc) {
beamer.capturePoint(camera, crc); beamer.capturePoint(camera, crc);
} }
......
...@@ -33,6 +33,7 @@ private: ...@@ -33,6 +33,7 @@ private:
vector<Point> border; vector<Point> border;
Point center; Point center;
Beamer beamer; Beamer beamer;
const char* CHAR_DELIM = "\t";
public: public:
Sandbox(); Sandbox();
...@@ -50,16 +51,12 @@ public: ...@@ -50,16 +51,12 @@ public:
Mat generateBorder(); Mat generateBorder();
int findEdgeBorder(int x, int y); int findEdgeBorder(int x, int y);
Mat editEdgeBorder(int selectedPoint, int x, int y); Mat editEdgeBorder(int selectedPoint, int x, int y);
tuple<Mat, vector<int>> detectPointToDetectBeamer(int indexPoint); tuple<Mat, vector<Vec3f>> detectPointToDetectBeamer(int indexPoint);
void capturePointToDetectBeamer(vector<int> crc); void capturePointToDetectBeamer(vector<Vec3f> crc);
void findBeamerPosition(); void findBeamerPosition();
void stopCamera(); void stopCamera();
const char* getA() {
return realSenseDevice.get_info(RS2_CAMERA_INFO_SERIAL_NUMBER);
}
int getB() {
return calibrate.getDistancePlan();
}
}; };
#endif // SANDBOX_H #endif // SANDBOX_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment