简体   繁体   中英

How to cast from cv::Vec3f to a float type?

Background

I am currently trying to build an autonomous drone using ROS on my Rapsberry Pi which is running an Ubuntu MATE 16.04 LTS . Solving the Computer Vision problem of recognising red circles as of now.

Code

I currently want to convert this:

cv::vector<cv::Vec3f> circles

into a an array of vectors of floats. However, I am well aware that a simple cast wouldn't suffice. So how should I approach this?

What about a simple loop?

std::vector<cv::Vec3f> circles;

// 'circles' filled somehow...

// Get 'circles' as a vector of vector of floats 'v'
std::vector<std::vector<float>> v(circles.size(), std::vector<float>(3));

for(size_t i=0; i<circles.size(); ++i) 
{
    const cv::Vec3f& c = circles[i];             
    v[i][0] = c[0];
    v[i][1] = c[1];
    v[i][2] = c[2];
}

Don't use cv::vector . Use std::vector instead. See here for more details.

Data Structure

Before you convert cv::vector<cv::Vec3f> type to float type

you have to understand what kind of data structure cv::vector<cv::Vec3f> is

It's like a 2d vector std::vector<cv::Vec3f>

在此处输入图片说明

so you cannot just assign a float variable to a 2d vector

You have to use another 2d vector with float type to store the data content

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM