Uncomment raspicam related lines
This commit is contained in:
parent
1bdadaa50f
commit
34c4234942
2 changed files with 49 additions and 57 deletions
|
@ -34,13 +34,12 @@ Camera::Camera():Camera(sm, 10){
|
||||||
* @param fps speed of sampling
|
* @param fps speed of sampling
|
||||||
*/
|
*/
|
||||||
Camera::Camera(int size, int fps) {
|
Camera::Camera(int size, int fps) {
|
||||||
this->SetSize(size);
|
this->SetSize(size);
|
||||||
#ifndef __FOR_PC__
|
#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_FORMAT, CV_8UC3);
|
this->cap.set(CV_CAP_PROP_FRAME_WIDTH, width);
|
||||||
// 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_HEIGHT, height);
|
this->cap.set(CV_CAP_PROP_FPS, fps);
|
||||||
// this->cap.set(CV_CAP_PROP_FPS, fps);
|
|
||||||
#endif /* __FOR_PC__ */
|
#endif /* __FOR_PC__ */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,37 +48,34 @@ Camera::Camera(int size, int fps) {
|
||||||
* @return True if camera is open, false otherwise
|
* @return True if camera is open, false otherwise
|
||||||
*/
|
*/
|
||||||
bool Camera::Open() {
|
bool Camera::Open() {
|
||||||
bool status = false;
|
bool status = false;
|
||||||
|
|
||||||
#ifdef __FOR_PC__
|
#ifdef __FOR_PC__
|
||||||
if (this->cap.open(0)) {
|
if (this->cap.open(0)) {
|
||||||
//this->cap.set(CV_CAP_PROP_FORMAT, CV_8UC3);
|
//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_WIDTH, width);
|
this->cap.set(CV_CAP_PROP_FRAME_HEIGHT, height);
|
||||||
// this->cap.set(CV_CAP_PROP_FRAME_HEIGHT, height);
|
|
||||||
|
|
||||||
status = true;
|
status = true;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
// TODO Throws Camera has no member cap
|
if (this->cap.open()) {
|
||||||
// if (this->cap.open()) {
|
cout << "Camera warmup 2sec" << endl << flush;
|
||||||
// cout << "Camera warmup 2sec" << endl << flush;
|
sleep(2);
|
||||||
// sleep(2);
|
cout << "Start capture" << endl << flush;
|
||||||
// cout << "Start capture" << endl << flush;
|
|
||||||
//
|
status = true;
|
||||||
// status = true;
|
}
|
||||||
// }
|
|
||||||
#endif /* __FOR_PC__ */
|
#endif /* __FOR_PC__ */
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Close and release camera
|
* Close and release camera
|
||||||
*/
|
*/
|
||||||
void Camera::Close() {
|
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
|
* @return Image taken from camera
|
||||||
*/
|
*/
|
||||||
Img Camera::Grab() {
|
Img Camera::Grab() {
|
||||||
ImageMat frame;
|
ImageMat frame;
|
||||||
|
|
||||||
#ifdef __FOR_PC__
|
#ifdef __FOR_PC__
|
||||||
cap >> frame;
|
cap >> frame;
|
||||||
Img capture = Img(frame);
|
Img capture = Img(frame);
|
||||||
#else
|
#else
|
||||||
// TODO Throws Camera has no member cap
|
cap.grab();
|
||||||
// cap.grab();
|
cap.retrieve(frame);
|
||||||
// cap.retrieve(frame);
|
|
||||||
|
|
||||||
#ifdef __INVERSE_COLOR__
|
#ifdef __INVERSE_COLOR__
|
||||||
cvtColor(frame, frame, CV_BGR2RGB);
|
cvtColor(frame, frame, CV_BGR2RGB);
|
||||||
#endif // __INVERSE_COLOR__
|
#endif // __INVERSE_COLOR__
|
||||||
|
|
||||||
Img capture = Img(frame);
|
Img capture = Img(frame);
|
||||||
#endif /* __FOR_PC__ */
|
#endif /* __FOR_PC__ */
|
||||||
|
|
||||||
return capture;
|
return capture;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -142,9 +137,7 @@ Img Camera::Grab() {
|
||||||
* @return true if camera is open, false otherwise
|
* @return true if camera is open, false otherwise
|
||||||
*/
|
*/
|
||||||
bool Camera::IsOpen() {
|
bool Camera::IsOpen() {
|
||||||
// TODO Throws Camera has no member cap
|
return cap.isOpened();
|
||||||
// return cap.isOpened();
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -175,10 +175,9 @@ std::list<Position> Img::SearchRobot(Arena arena) {
|
||||||
imgTraitment = this->img(arena.arena);
|
imgTraitment = this->img(arena.arena);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Cannot find symbols
|
cvtColor(imgTraitment, imgTraitment, CV_RGB2GRAY);
|
||||||
// cvtColor(imgTraitment, imgTraitment, CV_RGB2GRAY);
|
threshold(imgTraitment, imgTraitment, 128, 255, CV_THRESH_BINARY);
|
||||||
// threshold(imgTraitment, imgTraitment, 128, 255, CV_THRESH_BINARY);
|
findContours(imgTraitment, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, cv::Point(0, 0));
|
||||||
// findContours(imgTraitment, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, cv::Point(0, 0));
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < contours.size(); i++) {
|
for (unsigned int i = 0; i < contours.size(); i++) {
|
||||||
ImageMat m(contours[i]);
|
ImageMat m(contours[i]);
|
||||||
|
@ -235,23 +234,23 @@ std::list<Position> Img::SearchRobot(Arena arena) {
|
||||||
* @return Arena object with coordinate of outline, empty if no arena found
|
* @return Arena object with coordinate of outline, empty if no arena found
|
||||||
*/
|
*/
|
||||||
Arena Img::SearchArena() {
|
Arena Img::SearchArena() {
|
||||||
std::vector<std::vector<cv::Point> > contours;
|
std::vector<std::vector<cv::Point> > contours;
|
||||||
std::vector<cv::Point> approx;
|
std::vector<cv::Point> approx;
|
||||||
std::vector<cv::Vec4i> hierarchy;
|
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::Canny(imageTrt, imageTrt, 100, 200, 3); // detection d'angle
|
|
||||||
|
|
||||||
// findContours(imageTrt, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, cv::Point(0, 0));
|
ImageMat imageTrt;
|
||||||
for (unsigned int i = 0; i < contours.size(); i++) {
|
cv::cvtColor(this->img, imageTrt, CV_RGB2GRAY); // conversion en niveau de gris
|
||||||
approxPolyDP(ImageMat(contours[i]), approx, cv::arcLength(ImageMat(contours[i]), true)*0.1, true);
|
cv::threshold(imageTrt, imageTrt, 128, 255, CV_THRESH_BINARY); // Threshold les éléments les plus clair
|
||||||
if (approx.size() == 4 && fabs(cv::contourArea(contours[i])) > 100000) {
|
cv::Canny(imageTrt, imageTrt, 100, 200, 3); // detection d'angle
|
||||||
Arena rectangle;
|
|
||||||
rectangle.arena = cv::boundingRect(ImageMat(contours[i]));
|
findContours(imageTrt, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, cv::Point(0, 0));
|
||||||
return rectangle;
|
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();
|
return Arena();
|
||||||
|
|
Loading…
Reference in a new issue