Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ add_library (robocad-cpp SHARED
"src/internal/common/updaters.cpp"
)

target_link_options(robocad-cpp PRIVATE "LINKER:/NODEFAULTLIB:library")
if (MSVC)
target_link_options(robocad-cpp PRIVATE "LINKER:/NODEFAULTLIB:library")
endif()
target_link_libraries(robocad-cpp PRIVATE ${OpenCV_LIBS})
target_link_libraries(robocad-cpp PRIVATE Threads::Threads)

Expand Down
2 changes: 1 addition & 1 deletion include/internal/common/robot_configuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class DefaultAlgaritmConfiguration : public RobotConfiguration
{
public:
DefaultAlgaritmConfiguration() {
camera_index = 2;
camera_index = 0;
with_pi_blaster = false;
}

Expand Down
13 changes: 11 additions & 2 deletions include/shufflecad.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Shufflecad

void print_to_log(std::string message,
std::string message_type = LOG_INFO,
std::string color = "#cccccc");
std::string color = "#808080");

std::vector<ShuffleVariable*> variables_array;
std::vector<CameraVariable*> camera_variables_array;
Expand Down Expand Up @@ -156,8 +156,17 @@ class CameraVariable
std::vector<uint8_t> get_value()
{
std::lock_guard<std::mutex> lock(this->data_mutex);
// No frame yet (e.g. robot has no camera, or none captured so far):
// cv::imencode throws on an empty Mat, which would propagate out of the
// camera thread and terminate the whole program. Send a "null" placeholder.
if (this->value.empty())
return { 'n', 'u', 'l', 'l' };
std::vector<uchar> result;
cv::imencode(".jpg", this->value, result);
try {
cv::imencode(".jpg", this->value, result);
} catch (const cv::Exception&) {
return { 'n', 'u', 'l', 'l' };
}
return result;
}
private:
Expand Down
5 changes: 5 additions & 0 deletions src/internal/common/connection_real.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ ConnectionReal::ConnectionReal(Robot* robot, Updater* updater, RobotConfiguratio
try
{
camera_instance = new cv::VideoCapture(conf->camera_index);
if (camera_instance->isOpened())
robot->write_log("Camera opened on index " + std::to_string(conf->camera_index));
else
robot->write_log("Camera FAILED to open on index " + std::to_string(conf->camera_index) +
" (VideoCapture did not throw, but device is not available)");
}
catch (const std::exception& e)
{
Expand Down