Per creare delle tavole di calibrazione Charuco si puo' usare un proiettore ed un muro bianco. L'importante e' che la risoluzione dell'immagine proiettata sia uguale a quella massima del proiettore (in modo da non avere interpolazione sui bordi dei pixels)
Questo programma per Opencv 4.10 mostra l'immagine a schermo e salva su file un png. Per mostrare a schermo pieno si puo' usare il comando feh -f immagine.png
#include <opencv2/opencv.hpp>
#include <opencv2/aruco.hpp>
#include <iostream>
int main() {
int squaresX = 7;
int squaresY = 5;
float squareLength = 60; // in pixels (screen units)
float markerLength = 40; // in pixels
auto dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_4X4_50);
// Create ChArUco board using constructor (OpenCV 4.x syntax)
cv::aruco::CharucoBoard board(cv::Size(squaresX, squaresY), squareLength, markerLength, dictionary);
cv::Mat boardImage;
// Generate the board image
board.generateImage(cv::Size(1920, 1080 ), boardImage, 10, 1);
// Check if image was generated successfully
if (boardImage.empty()) {
std::cerr << "Failed to generate board image" << std::endl;
return -1;
}
cv::imwrite("charuco_board.png", boardImage);
// Display the board
cv::namedWindow("Projected Charuco Board", cv::WINDOW_NORMAL);
cv::setWindowProperty("Projected Charuco Board", cv::WND_PROP_FULLSCREEN, cv::WINDOW_FULLSCREEN);
cv::imshow("Projected Charuco Board", boardImage);
cv::waitKey(0);
cv::destroyAllWindows();
return 0;
}
Makefile
# Makefile for OpenCV 4.10.0 ChArUco Board Program
# Compiler
CXX = g++
# Program name
TARGET = charuco_board
# Source files
SOURCES = main.cpp
# Object files
OBJECTS = $(SOURCES:.cpp=.o)
# OpenCV version
OPENCV_VERSION = 4.10.0
# Compiler flags
CXXFLAGS = -std=c++11 -Wall -Wextra -O2
# OpenCV flags (using pkg-config)
OPENCV_CFLAGS = `pkg-config --cflags opencv4`
OPENCV_LIBS = `pkg-config --libs opencv4`
# Alternative manual OpenCV flags if pkg-config is not available
# Uncomment these lines and comment out the pkg-config lines above if needed
# OPENCV_INCLUDE = -I/usr/local/include/opencv4
# OPENCV_LIBS = -L/usr/local/lib -lopencv_core -lopencv_imgproc -lopencv_imgcodecs -lopencv_highgui -lopencv_aruco
# Default target
all: $(TARGET)
# Link the program
$(TARGET): $(OBJECTS)
$(CXX) $(OBJECTS) -o $(TARGET) $(OPENCV_LIBS)
# Compile source files
%.o: %.cpp
$(CXX) $(CXXFLAGS) $(OPENCV_CFLAGS) -c $< -o $@
# Clean build files
clean:
rm -f $(OBJECTS) $(TARGET)
# Install dependencies (Ubuntu/Debian)
install-deps:
sudo apt-get update
sudo apt-get install build-essential cmake pkg-config
sudo apt-get install libopencv-dev libopencv-contrib-dev
# Check OpenCV installation
check-opencv:
@echo "Checking OpenCV installation..."
@pkg-config --modversion opencv4 2>/dev/null || echo "OpenCV not found via pkg-config"
@echo "OpenCV compile flags:"
@pkg-config --cflags opencv4 2>/dev/null || echo "pkg-config not available"
@echo "OpenCV link flags:"
@pkg-config --libs opencv4 2>/dev/null || echo "pkg-config not available"
# Run the program
run: $(TARGET)
./$(TARGET)
# Debug build
debug: CXXFLAGS += -g -DDEBUG
debug: $(TARGET)
# Release build
release: CXXFLAGS += -O3 -DNDEBUG
release: $(TARGET)
# Help
help:
@echo "Available targets:"
@echo " all - Build the program (default)"
@echo " clean - Remove build files"
@echo " run - Build and run the program"
@echo " debug - Build with debug flags"
@echo " release - Build with release optimization"
@echo " install-deps - Install OpenCV dependencies (Ubuntu/Debian)"
@echo " check-opencv - Check OpenCV installation"
@echo " help - Show this help message"
# Phony targets
.PHONY: all clean run debug release install-deps check-opencv help
Nessun commento:
Posta un commento