Uncomment raspicam related lines

This commit is contained in:
Yohan Simard 2021-03-02 18:46:35 +01:00
parent 1bdadaa50f
commit 34c4234942
2 changed files with 49 additions and 57 deletions

View file

@ -36,11 +36,10 @@ Camera::Camera():Camera(sm, 10){
Camera::Camera(int size, int fps) {
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__ */
}
@ -54,21 +53,19 @@ bool Camera::Open() {
#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);
this->cap.set(CV_CAP_PROP_FRAME_WIDTH, width);
this->cap.set(CV_CAP_PROP_FRAME_HEIGHT, height);
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;
@ -78,8 +75,7 @@ bool Camera::Open() {
* Close and release camera
*/
void Camera::Close() {
// TODO Throws Camera has no member cap
// this->cap.release();
this->cap.release();
}
/**
@ -123,9 +119,8 @@ Img Camera::Grab() {
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);
@ -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();
}
/**

View file

@ -175,10 +175,9 @@ std::list<Position> 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]);
@ -238,15 +237,15 @@ Arena Img::SearchArena() {
std::vector<std::vector<cv::Point> > contours;
std::vector<cv::Point> approx;
std::vector<cv::Vec4i> 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::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));
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);
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]));