diff --git a/software/raspberry/superviseur-robot/lib/camera.cpp b/software/raspberry/superviseur-robot/lib/camera.cpp index 0619e60..20c912f 100644 --- a/software/raspberry/superviseur-robot/lib/camera.cpp +++ b/software/raspberry/superviseur-robot/lib/camera.cpp @@ -34,13 +34,12 @@ Camera::Camera():Camera(sm, 10){ * @param fps speed of sampling */ Camera::Camera(int size, int fps) { - this->SetSize(size); + this->SetSize(size); #ifndef __FOR_PC__ -// TODO Throws Camera has no member cap -// this->cap.set(CV_CAP_PROP_FORMAT, CV_8UC3); -// this->cap.set(CV_CAP_PROP_FRAME_WIDTH, width); -// this->cap.set(CV_CAP_PROP_FRAME_HEIGHT, height); -// this->cap.set(CV_CAP_PROP_FPS, fps); + this->cap.set(CV_CAP_PROP_FORMAT, CV_8UC3); + this->cap.set(CV_CAP_PROP_FRAME_WIDTH, width); + this->cap.set(CV_CAP_PROP_FRAME_HEIGHT, height); + this->cap.set(CV_CAP_PROP_FPS, fps); #endif /* __FOR_PC__ */ } @@ -49,37 +48,34 @@ Camera::Camera(int size, int fps) { * @return True if camera is open, false otherwise */ bool Camera::Open() { - bool status = false; + bool status = false; #ifdef __FOR_PC__ - if (this->cap.open(0)) { - //this->cap.set(CV_CAP_PROP_FORMAT, CV_8UC3); -// Throw compile errors -// this->cap.set(CV_CAP_PROP_FRAME_WIDTH, width); -// this->cap.set(CV_CAP_PROP_FRAME_HEIGHT, height); + if (this->cap.open(0)) { + //this->cap.set(CV_CAP_PROP_FORMAT, CV_8UC3); + this->cap.set(CV_CAP_PROP_FRAME_WIDTH, width); + this->cap.set(CV_CAP_PROP_FRAME_HEIGHT, height); - status = true; - } + status = true; + } #else -// TODO Throws Camera has no member cap -// if (this->cap.open()) { -// cout << "Camera warmup 2sec" << endl << flush; -// sleep(2); -// cout << "Start capture" << endl << flush; -// -// status = true; -// } + if (this->cap.open()) { + cout << "Camera warmup 2sec" << endl << flush; + sleep(2); + cout << "Start capture" << endl << flush; + + status = true; + } #endif /* __FOR_PC__ */ - return status; + return status; } /** * Close and release camera */ void Camera::Close() { -// TODO Throws Camera has no member cap -// this->cap.release(); + this->cap.release(); } /** @@ -117,24 +113,23 @@ void Camera::SetSize(int size) { * @return Image taken from camera */ Img Camera::Grab() { - ImageMat frame; + ImageMat frame; #ifdef __FOR_PC__ - cap >> frame; - Img capture = Img(frame); + cap >> frame; + Img capture = Img(frame); #else -// TODO Throws Camera has no member cap -// cap.grab(); -// cap.retrieve(frame); + cap.grab(); + cap.retrieve(frame); #ifdef __INVERSE_COLOR__ - cvtColor(frame, frame, CV_BGR2RGB); + cvtColor(frame, frame, CV_BGR2RGB); #endif // __INVERSE_COLOR__ - Img capture = Img(frame); + Img capture = Img(frame); #endif /* __FOR_PC__ */ - return capture; + return capture; } /** @@ -142,9 +137,7 @@ Img Camera::Grab() { * @return true if camera is open, false otherwise */ bool Camera::IsOpen() { -// TODO Throws Camera has no member cap -// return cap.isOpened(); - return false; + return cap.isOpened(); } /** diff --git a/software/raspberry/superviseur-robot/lib/img.cpp b/software/raspberry/superviseur-robot/lib/img.cpp index dde3176..3626886 100644 --- a/software/raspberry/superviseur-robot/lib/img.cpp +++ b/software/raspberry/superviseur-robot/lib/img.cpp @@ -175,10 +175,9 @@ std::list Img::SearchRobot(Arena arena) { imgTraitment = this->img(arena.arena); } -// TODO Cannot find symbols -// cvtColor(imgTraitment, imgTraitment, CV_RGB2GRAY); -// threshold(imgTraitment, imgTraitment, 128, 255, CV_THRESH_BINARY); -// findContours(imgTraitment, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, cv::Point(0, 0)); + cvtColor(imgTraitment, imgTraitment, CV_RGB2GRAY); + threshold(imgTraitment, imgTraitment, 128, 255, CV_THRESH_BINARY); + findContours(imgTraitment, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, cv::Point(0, 0)); for (unsigned int i = 0; i < contours.size(); i++) { ImageMat m(contours[i]); @@ -235,23 +234,23 @@ std::list Img::SearchRobot(Arena arena) { * @return Arena object with coordinate of outline, empty if no arena found */ Arena Img::SearchArena() { - std::vector > contours; - std::vector approx; - std::vector hierarchy; -// Commented lines throw compile errors - ImageMat imageTrt; -// cv::cvtColor(this->img, imageTrt, CV_RGB2GRAY); // conversion en niveau de gris -// cv::threshold(imageTrt, imageTrt, 128, 255, CV_THRESH_BINARY); // Threshold les éléments les plus clair - cv::Canny(imageTrt, imageTrt, 100, 200, 3); // detection d'angle + std::vector > contours; + std::vector approx; + std::vector hierarchy; -// findContours(imageTrt, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, cv::Point(0, 0)); - for (unsigned int i = 0; i < contours.size(); i++) { - approxPolyDP(ImageMat(contours[i]), approx, cv::arcLength(ImageMat(contours[i]), true)*0.1, true); - if (approx.size() == 4 && fabs(cv::contourArea(contours[i])) > 100000) { - Arena rectangle; - rectangle.arena = cv::boundingRect(ImageMat(contours[i])); - return rectangle; - } + ImageMat imageTrt; + cv::cvtColor(this->img, imageTrt, CV_RGB2GRAY); // conversion en niveau de gris + cv::threshold(imageTrt, imageTrt, 128, 255, CV_THRESH_BINARY); // Threshold les éléments les plus clair + cv::Canny(imageTrt, imageTrt, 100, 200, 3); // detection d'angle + + findContours(imageTrt, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, cv::Point(0, 0)); + for (unsigned int i = 0; i < contours.size(); i++) { + approxPolyDP(ImageMat(contours[i]), approx, cv::arcLength(ImageMat(contours[i]), true) * 0.1, true); + if (approx.size() == 4 && fabs(cv::contourArea(contours[i])) > 100000) { + Arena rectangle; + rectangle.arena = cv::boundingRect(ImageMat(contours[i])); + return rectangle; + } } return Arena();