Giter Club home page Giter Club logo

Comments (2)

huang-shijie avatar huang-shijie commented on July 17, 2024

i find this question is caused by the .toimagemsg() function not work. it seems is due to the encoding stratage. the depth image encoding is 32FC1. dose the cv bridge support this encoding stratage? the imshow() seems ok,but the ros publish image is false , and i use the ubuntu 20.04 ,ros noetic.

drone2

`void DroneDetector::rcvDepthImgCallback(const sensor_msgs::ImageConstPtr& depth_img)
{
/* get depth image */
cv_bridge::CvImagePtr cv_ptr;
cv_ptr = cv_bridge::toCvCopy(depth_img, depth_img->encoding);
cv_ptr->image.copyTo(depth_img_);

// cv::Mat depth_img_ = cv_bridge::toCvShare(depth_img)->image;

debug_start_time_ = ros::Time::now();

Eigen::Vector2i true_pixel[max_drone_num_]; //数组
for (int i = 0; i < max_drone_num_; i++) {
if (in_depth_[i]) {
detect(i, true_pixel[i]);
}
}

cv_bridge::CvImage out_msg;
for (int i = 0; i < max_drone_num_; i++) {
if (in_depth_[i]) {
// erase hit pixels in depth
for(int k = 0; k < int(hit_pixels_[i].size()); k++) {
// depth_img_.at(hit_pixels_[i]k, hit_pixels_[i]k) = 0;
uint16_t row_ptr;
row_ptr = depth_img_.ptr<uint16_t>(hit_pixels_[i]k);
(
(row_ptr+hit_pixels_[i]k)) = 0.0;
// std::cout << "remove ______" <<std::endl;
}
}
}
cv::imshow("Image Viewer", depth_img
);
cv::waitKey(10);
// depth_img

debug_end_time
= ros::Time::now();
// ROS_WARN("cost_total_time = %lf", (debug_end_time
- debug_start_time
).toSec()*1000.0);
out_msg.header = depth_img->header;
out_msg.encoding = depth_img->encodingsss;
// std::cout << "remove __________"<< out_msg.encoding <<std::endl;
out_msg.image = depth_img
.clone();

// sensor_msgs::ImagePtr modified_depth_msg = cv_bridge::CvImage(depth_img->header, "32FC1", depth_img_).toImageMsg();

new_depth_img_pub_.publish(out_msg.toImageMsg());

std_msgs::String msg;
std::stringstream ss;
if(debug_flag_) {
for (int i = 0; i < max_drone_num_; i++) {
if (in_depth_[i]) {
// add bound box in colormap
// cv::Rect rect(bbox_lu.x, bbox_lu.y, bbox_rd.x, bbox_rd.y);//左上坐标(x,y)和矩形的长(x)宽(y)
cv::rectangle(depth_img
, cv::Rect(searchbox_lu
[i], searchbox_rd
[i]), cv::Scalar(0, 0, 0), 5, cv::LINE_8, 0);
cv::rectangle(depth_img
, cv::Rect(boundingbox_lu_[i], boundingbox_rd_[i]), cv::Scalar(0, 0, 0), 5, cv::LINE_8, 0);
if (debug_detect_result_[i] == 1) {
ss << "no enough " << hit_pixels_[i].size();
} else if(debug_detect_result_[i] == 2) {
ss << "success";
}
} else {
ss << "no detect";
}
}
out_msg.header = depth_img->header;
out_msg.encoding = depth_img->encoding;
out_msg.image = depth_img_.clone();
debug_depth_img_pub_.publish(out_msg.toImageMsg());
msg.data = ss.str();
debug_info_pub_.publish(msg);
}
}`

from ego-planner-v2.

bigsuperZZZX avatar bigsuperZZZX commented on July 17, 2024

This part of code may help:

if (img->encoding == sensor_msgs::image_encodings::TYPE_32FC1)

from ego-planner-v2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.