forked from floratest1/SpireCV
add a new drawTargetsInFrame() for single aruco tracking.
This commit is contained in:
parent
6bd48bac2b
commit
ddb157b374
|
@ -377,6 +377,19 @@ protected:
|
|||
double _exposure;
|
||||
};
|
||||
|
||||
void drawTargetsInFrame(
|
||||
cv::Mat& img_,
|
||||
const TargetsInFrame& tgts_,
|
||||
int aruco_track_id,
|
||||
bool with_all=true,
|
||||
bool with_category=false,
|
||||
bool with_tid=false,
|
||||
bool with_seg=false,
|
||||
bool with_box=false,
|
||||
bool with_ell=false,
|
||||
bool with_aruco=false,
|
||||
bool with_yaw=false
|
||||
);
|
||||
|
||||
void drawTargetsInFrame(
|
||||
cv::Mat& img_,
|
||||
|
|
|
@ -367,6 +367,56 @@ void UDPServer::send(const TargetsInFrame& tgts_)
|
|||
int r = sendto(this->_sockfd, upd_msg, mp, 0, (struct sockaddr *)&this->_servaddr, sizeof(this->_servaddr));
|
||||
}
|
||||
|
||||
void drawTargetsInFrame(
|
||||
cv::Mat& img_,
|
||||
const TargetsInFrame& tgts_,
|
||||
int aruco_track_id,
|
||||
bool with_all,
|
||||
bool with_category,
|
||||
bool with_tid,
|
||||
bool with_seg,
|
||||
bool with_box,
|
||||
bool with_ell,
|
||||
bool with_aruco,
|
||||
bool with_yaw
|
||||
)
|
||||
{
|
||||
if (tgts_.rois.size() > 0 )
|
||||
{
|
||||
cv::Mat image_ret;
|
||||
cv::addWeighted(img_, 0.5, cv::Mat::zeros(cv::Size(img_.cols, img_.rows), CV_8UC3), 0, 0, image_ret);
|
||||
cv::Rect roi = cv::Rect(tgts_.rois[0].x1, tgts_.rois[0].y1, tgts_.rois[0].x2 - tgts_.rois[0].x1, tgts_.rois[0].y2 - tgts_.rois[0].y1);
|
||||
img_(roi).copyTo(image_ret(roi));
|
||||
image_ret.copyTo(img_);
|
||||
}
|
||||
std::vector<std::vector<cv::Point2f> > aruco_corners;
|
||||
std::vector<int> aruco_ids;
|
||||
for (Target tgt : tgts_.targets)
|
||||
{
|
||||
if ((with_all || with_aruco) && tgt.has_aruco && (tgt.tracked_id == aruco_track_id))
|
||||
{
|
||||
std::vector<cv::Point2f> a_corners;
|
||||
int a_id;
|
||||
if (tgt.getAruco(a_id, a_corners)) { aruco_ids.push_back(a_id); aruco_corners.push_back(a_corners); }
|
||||
cv::circle(img_, cv::Point(int(tgt.cx * tgts_.width), int(tgt.cy * tgts_.height)), 4, cv::Scalar(0,255,0), 2);
|
||||
}
|
||||
if ((with_all || with_box) && tgt.has_box && (tgt.tracked_id == aruco_track_id))
|
||||
{
|
||||
Box b;
|
||||
tgt.getBox(b);
|
||||
cv::rectangle(img_, cv::Rect(b.x1, b.y1, b.x2-b.x1+1, b.y2-b.y1+1), cv::Scalar(0,0,255), 1, 1, 0);
|
||||
if ((with_all || with_category) && tgt.has_category)
|
||||
{
|
||||
cv::putText(img_, tgt.category, cv::Point(b.x1, b.y1-4), cv::FONT_HERSHEY_DUPLEX, 0.4, cv::Scalar(255,0,0));
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((with_all || with_aruco) && aruco_ids.size() > 0)
|
||||
{
|
||||
cv::aruco::drawDetectedMarkers(img_, aruco_corners, aruco_ids);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void drawTargetsInFrame(
|
||||
cv::Mat& img_,
|
||||
|
|
Loading…
Reference in New Issue