Possibilité de désactiver opencv4 avec cmake

This commit is contained in:
Arnaud Vergnet 2021-03-03 08:13:05 +01:00
parent 5f99ea9f0e
commit d18621f6eb
3 changed files with 21 additions and 10 deletions

View file

@ -27,7 +27,7 @@ add_library(lib
) )
target_include_directories(lib PUBLIC lib) target_include_directories(lib PUBLIC lib)
target_link_libraries(lib base64) target_link_libraries(lib base64)
target_compile_definitions(lib PUBLIC __FOR_PC__ __SIMULATION__ __WITH_ARUCO__) target_compile_definitions(lib PUBLIC __FOR_PC__ __SIMULATION__ __WITH_ARUCO__ __WITH_OPENCV4__)
# Compile main executable # Compile main executable
add_executable(main main.cpp tasks.cpp tasks.h) add_executable(main main.cpp tasks.cpp tasks.h)

View file

@ -52,10 +52,15 @@ bool Camera::Open() {
#ifdef __FOR_PC__ #ifdef __FOR_PC__
if (this->cap.open(0)) { if (this->cap.open(0)) {
//this->cap.set(CAP_PROP_FORMAT, CV_8UC3); #ifdef __WITH_OPENCV4__
this->cap.set(CAP_PROP_FRAME_WIDTH, width); //this->cap.set(CAP_PROP_FORMAT, CV_8UC3);
this->cap.set(CAP_PROP_FRAME_HEIGHT, height); this->cap.set(CAP_PROP_FRAME_WIDTH, width);
this->cap.set(CAP_PROP_FRAME_HEIGHT, height);
#else
//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);
#endif /* __WITH_OPENCV4__ */
status = true; status = true;
} }
#else #else

View file

@ -239,11 +239,17 @@ Arena Img::SearchArena() {
std::vector<cv::Vec4i> hierarchy; std::vector<cv::Vec4i> hierarchy;
ImageMat imageTrt; ImageMat imageTrt;
cv::cvtColor(this->img, imageTrt, cv::COLOR_RGB2GRAY); // conversion en niveau de gris #ifdef __WITH_OPENCV4__
cv::threshold(imageTrt, imageTrt, 128, 255, cv::THRESH_BINARY); // Threshold les éléments les plus clair cv::cvtColor(this->img, imageTrt, cv::COLOR_RGB2GRAY); // conversion en niveau de gris
cv::Canny(imageTrt, imageTrt, 100, 200, 3); // detection d'angle 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));
#else
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));
#endif
for (unsigned int i = 0; i < contours.size(); i++) { 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) { if (approx.size() == 4 && fabs(cv::contourArea(contours[i])) > 100000) {