I am struggling to debug a segmentation fault. Any help is appreciated! The node just crashes whenever I launch it and following is the seg fault I am getting when running through gdb:
Thread 7 "nodelet" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xfffff19ac170 (LWP 12693)]
0x0000ffffe1a95808 in cv::findContours(cv::_InputArray const&, cv::_OutputArray const&, int, int, cv::Point_<int>) ()
from /lib/aarch64-linux-gnu/libopencv_imgproc.so.4.2
Posting snipet of the code where I am getting the error:
#include <poll_detect/poll_detect.h>
PollDetect::PollDetect(const std::string& cameraName, ros::NodeHandle& nh)
: m_CameraName_(cameraName) {
image_sub = nh.subscribe("/camera_1/image_raw", 10, &PollDetect::inputImageCb, this);
image_pub = nh.advertise<sensor_msgs::Image>("/camera_1/pub_image", 10);
}
// Input image callback
void PollDetect::inputImageCb(const sensor_msgs::Image::ConstPtr& msg) {
cv::Mat input = convertToCvMat(msg);
cv::Mat filteredImage;
apply(input, filteredImage);
std::vector<cv::Rect> detectedPoll = detect(filteredImage);
}
// Convert ROS image to OpenCV image
cv::Mat PollDetect::convertToCvMat(const sensor_msgs::ImageConstPtr& imageMsg) {
cv_bridge::CvImagePtr cvPtr;
try {
cvPtr = cv_bridge::toCvCopy(imageMsg, sensor_msgs::image_encodings::BGR8);
} catch (cv_bridge::Exception& e) {
ROS_ERROR("cv_bridge exception: %s", e.what());
return cv::Mat();
}
return cvPtr->image;
}
// Convert OpenCV image to ROS image
sensor_msgs::Image PollDetect::convertToRosImage(const cv::Mat& cvImage) {
return *cv_bridge::CvImage(std_msgs::Header(), "mono8", cvImage).toImageMsg();
}
// Apply HSV filter
void PollDetect::apply(const cv::Mat& input, cv::Mat& output) {
cv::Mat hsvImage;
cv::cvtColor(input, hsvImage, cv::COLOR_BGR2HSV);
cv::inRange(hsvImage, m_LowerBounds_, m_UpperBounds_, output);
}
// Poll detector
std::vector<cv::Rect> PollDetect::detect(const cv::Mat& input) {
std::vector<std::vector<cv::Point>> contours;
std::vector<cv::Rect> detections;
cv::findContours(input, contours, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE);
std::transform(contours.cbegin(), contours.cend(), std::back_inserter(detections),
[](const std::vector<cv::Point>& contour) { return cv::boundingRect(contour); });
return detections;
}
image
instead ofinput
$\endgroup$input
in my question.. still getting the segmentation fault $\endgroup$