本文整理匯總了C++中CBlob::GetEllipse方法的典型用法代碼示例。如果您正苦於以下問題:C++ CBlob::GetEllipse方法的具體用法?C++ CBlob::GetEllipse怎麽用?C++ CBlob::GetEllipse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類CBlob
的用法示例。
在下文中一共展示了CBlob::GetEllipse方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: pcCallback
void TabletopDetector::pcCallback(sensor_msgs::PointCloud2::ConstPtr pc_msg) {
if(!pc_lock.try_lock())
return;
pcl::PointCloud<pcl::PointXYZRGB> pc_full, pc_full_frame;
pcl::fromROSMsg(*pc_msg, pc_full);
string base_frame("/base_link");
ros::Time now = ros::Time::now();
tf_listener.waitForTransform(pc_msg->header.frame_id, base_frame, now, ros::Duration(3.0));
pcl_ros::transformPointCloud(base_frame, pc_full, pc_full_frame, tf_listener);
// pc_full_frame is in torso lift frame
cv::Mat cur_height_img = cv::Mat::zeros(imgx, imgy, CV_8U);
BOOST_FOREACH(const pcl::PointXYZRGB& pt, pc_full_frame.points) {
if(pt.x != pt.x || pt.y != pt.y || pt.z != pt.z)
continue;
int32_t x, y, z;
x = (pt.x - minx)/(maxx-minx) * imgx;
y = (pt.y - miny)/(maxy-miny) * imgy;
z = (pt.z - minz)/(maxz-minz) * 256;
if(x < 0 || y < 0) continue;
if(x >= imgx || y >= imgy) continue;
if(z < 0 || z >= 256) continue;
if(cur_height_img.at<uint8_t>(x, y) == 0 || cur_height_img.at<uint8_t>(x, y) < (uint8_t) z)
cur_height_img.at<uint8_t>(x, y) = (uint8_t) z;
}
cv::max(height_img_max, cur_height_img, height_img_max);
cv::Mat cur_height_img_flt;
cur_height_img.convertTo(cur_height_img_flt, CV_32F);
height_img_sum += cur_height_img_flt;
cv::Mat cur_count(imgx, imgy, CV_8U);
cur_count = (cur_height_img > 0) / 255;
cv::Mat cur_count_flt(imgx, imgy, CV_32F);
cur_count.convertTo(cur_count_flt, CV_32F);
height_img_count += cur_count_flt;
cv::Mat height_img_avg_flt = height_img_sum / height_img_count;
cv::Mat height_img_avg(imgx, imgy, CV_8U);
height_img_avg_flt.convertTo(height_img_avg, CV_8U);
height_img_avg = height_img_max;
cv::Mat height_hist(256, 1, CV_32F, cv::Scalar(0));
for(uint32_t x=0;x<imgx;x++)
for(uint32_t y=0;y<imgy;y++) {
if(height_img_avg.at<uint8_t>(x,y) == 255)
height_img_avg.at<uint8_t>(x,y) = 0;
if(height_img_avg.at<uint8_t>(x,y) != 0) {
height_hist.at<float>(height_img_avg.at<uint8_t>(x,y), 0)++;
}
}
////////////////////// Finding best table height /////////////////////////
uint32_t gfiltlen = 25;
float stddev = 256/(maxz-minz) * 0.015;
cv::Mat gauss_filt(gfiltlen, 1, CV_32F, cv::Scalar(0));
for(uint32_t i=0;i<gfiltlen;i++)
gauss_filt.at<float>(i,0) = 0.39894 / stddev * std::exp(-(i-((float)gfiltlen)/2)*(i-((float)gfiltlen)/2)/(2*stddev*stddev));
//cout << gauss_filt;
uint32_t maxval = 0, maxidx = 0;
for(uint32_t i=0;i<256-gfiltlen;i++) {
uint32_t sum = 0;
for(uint32_t j=0;j<gfiltlen;j++)
sum += height_hist.at<float>(i+j,0) * gauss_filt.at<float>(j,0);
if(sum > maxval && i != 0) {
maxval = sum;
maxidx = i+gfiltlen/2;
}
}
int32_t table_height = ((int32_t)maxidx);
//printf("%d %d, ", maxval, maxidx);
/////////////////////////// Getting table binary /////////////////////
cv::Mat height_img_thresh(imgx, imgy, CV_8U);
height_img_thresh = height_img_avg.clone();
for(uint32_t x=0;x<imgx;x++)
for(uint32_t y=0;y<imgy;y++) {
if(std::fabs(table_height - ((int32_t)height_img_thresh.at<uint8_t>(x,y))) < stddev*2)
height_img_thresh.at<uint8_t>(x,y) = 255;
else
height_img_thresh.at<uint8_t>(x,y) = 0;
}
//////////////////////////////////////////////////////////////////
IplImage height_img_thresh_ipl = height_img_thresh;
IplConvKernel* element = cvCreateStructuringElementEx(3, 3, 1, 1, CV_SHAPE_RECT);
cvMorphologyEx(&height_img_thresh_ipl, &height_img_thresh_ipl, NULL, element, CV_MOP_CLOSE, num_closes);
//cvMorphologyEx(&height_img_thresh, &height_img_thresh, NULL, element, CV_MOP_OPEN, 2);
cv::Mat height_img_thresh_blob = height_img_thresh.clone();
IplImage blob_img = height_img_thresh_blob;
CBlobResult blobs = CBlobResult(&blob_img, NULL, 0);
//blobs.Filter(blobs, B_EXCLUDE, CBlobGetArea(), B_LESS, 10);
CBlob biggestblob;
blobs.GetNthBlob(CBlobGetArea(), 0, biggestblob);
cv::Mat table_blob(imgx, imgy, CV_8U, cv::Scalar(0)); IplImage table_blob_img = table_blob;
biggestblob.FillBlob(&table_blob_img, cv::Scalar(150));
//drawCvBox2D(blob_img, table_roi, cv::Scalar(50), 1);
CvBox2D table_roi = biggestblob.GetEllipse(); table_roi.angle *= CV_PI/180;
cv::Mat table_hull(imgx, imgy, CV_8U, cv::Scalar(0));
IplImage hull_img = table_hull;
fillCvBox2D(hull_img, table_roi, cv::Scalar(255));
//printf("Cvbox: %f, %f, %f, %f, %f\n", table_roi.center.x, table_roi.center.y, table_roi.size.width, table_roi.size.height, table_roi.angle);
//.........這裏部分代碼省略.........
示例2: pcCallback
void TabletopSegmentor::pcCallback(sensor_msgs::PointCloud2::ConstPtr pc_msg) {
if(!pc_lock.try_lock())
return;
pcl::PointCloud<pcl::PointXYZRGB> pc_full, pc_full_frame;
pcl::fromROSMsg(*pc_msg, pc_full);
string base_frame("/base_link");
ros::Time now = ros::Time::now();
tf_listener.waitForTransform(pc_msg->header.frame_id, base_frame, now, ros::Duration(3.0));
pcl_ros::transformPointCloud(base_frame, pc_full, pc_full_frame, tf_listener);
// pc_full_frame is in torso lift frame
cv::Mat cur_height_img = cv::Mat::zeros(imgx, imgy, CV_8U);
BOOST_FOREACH(const pcl::PointXYZRGB& pt, pc_full_frame.points) {
if(pt.x != pt.x || pt.y != pt.y || pt.z != pt.z)
continue;
int32_t x, y, z;
x = (pt.x - minx)/(maxx-minx) * imgx;
y = (pt.y - miny)/(maxy-miny) * imgy;
z = (pt.z - minz)/(maxz-minz) * 256;
if(x < 0 || y < 0) continue;
if(x >= imgx || y >= imgy) continue;
if(z < 0 || z >= 256) continue;
if(cur_height_img.at<uint8_t>(x, y) == 0 || cur_height_img.at<uint8_t>(x, y) < (uint8_t) z)
cur_height_img.at<uint8_t>(x, y) = (uint8_t) z;
}
cv::max(height_img_max, cur_height_img, height_img_max);
cv::Mat cur_height_img_flt;
cur_height_img.convertTo(cur_height_img_flt, CV_32F);
height_img_sum += cur_height_img_flt;
cv::Mat cur_count(imgx, imgy, CV_8U);
cur_count = (cur_height_img > 0) / 255;
cv::Mat cur_count_flt(imgx, imgy, CV_32F);
cur_count.convertTo(cur_count_flt, CV_32F);
height_img_count += cur_count_flt;
cv::Mat height_img_avg_flt = height_img_sum / height_img_count;
cv::Mat height_img_avg(imgx, imgy, CV_8U);
height_img_avg_flt.convertTo(height_img_avg, CV_8U);
height_img_avg = height_img_max;
cv::Mat height_hist(256, 1, CV_32F, cv::Scalar(0));
for(uint32_t x=0;x<imgx;x++)
for(uint32_t y=0;y<imgy;y++) {
if(height_img_avg.at<uint8_t>(x,y) == 255)
height_img_avg.at<uint8_t>(x,y) = 0;
if(height_img_avg.at<uint8_t>(x,y) != 0) {
height_hist.at<float>(height_img_avg.at<uint8_t>(x,y), 0)++;
}
}
////////////////////// Finding best table height /////////////////////////
uint32_t gfiltlen = 25;
float stddev = 256/(maxz-minz) * 0.015;
cv::Mat gauss_filt(gfiltlen, 1, CV_32F, cv::Scalar(0));
for(uint32_t i=0;i<gfiltlen;i++)
gauss_filt.at<float>(i,0) = 0.39894 / stddev * std::exp(-(i-((float)gfiltlen)/2)*(i-((float)gfiltlen)/2)/(2*stddev*stddev));
//cout << gauss_filt;
uint32_t maxval = 0, maxidx = 0;
for(uint32_t i=0;i<256-gfiltlen;i++) {
uint32_t sum = 0;
for(uint32_t j=0;j<gfiltlen;j++)
sum += height_hist.at<float>(i+j,0) * gauss_filt.at<float>(j,0);
if(sum > maxval && i != 0) {
maxval = sum;
maxidx = i+gfiltlen/2;
}
}
int32_t table_height = ((int32_t)maxidx);
//printf("%d %d, ", maxval, maxidx);
/////////////////////////// Getting table binary /////////////////////
cv::Mat height_img_thresh(imgx, imgy, CV_8U);
height_img_thresh = height_img_avg.clone();
for(uint32_t x=0;x<imgx;x++)
for(uint32_t y=0;y<imgy;y++) {
if(std::fabs(table_height - ((int32_t)height_img_thresh.at<uint8_t>(x,y))) < stddev*2)
height_img_thresh.at<uint8_t>(x,y) = 255;
else
height_img_thresh.at<uint8_t>(x,y) = 0;
}
//////////////////////////////////////////////////////////////////
IplImage height_img_thresh_ipl = height_img_thresh;
IplConvKernel* element = cvCreateStructuringElementEx(3, 3, 1, 1, CV_SHAPE_RECT);
cvMorphologyEx(&height_img_thresh_ipl, &height_img_thresh_ipl, NULL, element, CV_MOP_CLOSE, num_closes);
//cvMorphologyEx(&height_img_thresh, &height_img_thresh, NULL, element, CV_MOP_OPEN, 2);
cv::Mat height_img_thresh_blob = height_img_thresh.clone();
IplImage blob_img = height_img_thresh_blob;
CBlobResult blobs = CBlobResult(&blob_img, NULL, 0);
//blobs.Filter(blobs, B_EXCLUDE, CBlobGetArea(), B_LESS, 10);
CBlob biggestblob;
blobs.GetNthBlob(CBlobGetArea(), 0, biggestblob);
cv::Mat table_blob(imgx, imgy, CV_8U, cv::Scalar(0)); IplImage table_blob_img = table_blob;
biggestblob.FillBlob(&table_blob_img, cv::Scalar(150));
//drawCvBox2D(blob_img, table_roi, cv::Scalar(50), 1);
CvBox2D table_roi = biggestblob.GetEllipse(); table_roi.angle *= CV_PI/180;
cv::Mat table_hull(imgx, imgy, CV_8U, cv::Scalar(0));
IplImage hull_img = table_hull;
fillCvBox2D(hull_img, table_roi, cv::Scalar(255));
//printf("Cvbox: %f, %f, %f, %f, %f\n", table_roi.center.x, table_roi.center.y, table_roi.size.width, table_roi.size.height, table_roi.angle);
//.........這裏部分代碼省略.........