本文整理汇总了C++中al::ALValue::getSize方法的典型用法代码示例。如果您正苦于以下问题:C++ ALValue::getSize方法的具体用法?C++ ALValue::getSize怎么用?C++ ALValue::getSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类al::ALValue
的用法示例。
在下文中一共展示了ALValue::getSize方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ParseWordRecognizedArray
void ParseWordRecognizedArray(std::vector<WordConfidencePair>& results, const AL::ALValue& value, float recognitionThreshold)
{
// unexpected data
if (value.getType() != AL::ALValue::TypeArray)
MODULE_ERROR("invalid array type");
// unexpected data
if (value.getSize() % 2 != 0)
MODULE_ERROR("invalid array size");
for (int i = 0; i < (int)value.getSize(); i += 2)
{
AL::ALValue wordValue = value[i];
AL::ALValue confidenceValue = value[i + 1];
float confidence = confidenceValue.operator float &();
if (confidence >= recognitionThreshold)
{
WordConfidencePair pair = { wordValue.toString(), confidence };
results.push_back(pair);
}
}
std::sort(results.begin(), results.end(), WordConfidencePairComparison());
}
示例2: callback
void NaoMarkServiceDetection::callback(const std::string &key, const AL::ALValue &value, const AL::ALValue &msg)
{
AL::ALValue marks = fMemoryProxy.getData("LandmarkDetected");
if(marks.getSize() > 0 && !_isMarkFound)
{
int TimeStampField = marks[0][1];
if((int)marks[1][0][1][0] == _markToFind)
{
if((float)marks[1][0][0][3] < 0.2f)
{
if(_isAllowedToMove)
motionProxy->moveToward(0.5f,0,marks[1][0][0][1]);
_naoMarkDetected = true;
}
else
{
motionProxy->moveToward(0,0,0);
_isMarkFound = true;
}
}
else
motionProxy->moveToward(0,0,0);
}
}
示例3: identifySpeaker
/** This method try to match a localized sound to an identified face, and update
* accordingly the corresponding 'human'.
*
* If none is found, a 'virtual' human called 'unknown_speaker' is created, with an
* approximate position.
*/
void InteractionMonitor::identifySpeaker(const AL::ALValue &sounds, map<string, Human>& humans) {
// according to the doc
// http://www.aldebaran-robotics.com/documentation/naoqi/audio/alaudiosourcelocalization.html
// only one sound may be localized at a given step.
if (sounds.getSize() == 0) return;
map<string, Human>::iterator it;
Human h = makeHuman("unknown_speaker", sounds[0][1][0], sounds[0][1][1]);
for (it=humans.begin(); it!=humans.end(); ++it)
{
if (distance(h, it->second) < MAX_DISTANCE_HUMAN_SOUND) {
it->second.speaking = true;
return;
}
}
humans[h.id] = h;
}
示例4: detect
bool vpFaceTrackerOkao::detect()
{
m_message.clear();
m_polygon.clear();
m_nb_objects = 0;
m_faces.clear();
m_scores.clear();
bool target_found = false;
AL::ALValue result = m_mem_proxy.getData("FaceDetected");
//-- Detect faces
if (result.getSize() >=2)
{
//std::cout << "face" << std::endl;
AL::ALValue info_face_array = result[1];
target_found = true;
double min_dist = m_image_width*m_image_height;
unsigned int index_closest_cog = 0;
vpImagePoint closest_cog;
for (unsigned int i = 0; i < info_face_array.getSize()-1; i++ )
{
//Extract face info
// Face Detected [1]/ First face [0]/ Shape Info [0]/ Alpha [1]
float alpha = result[1][i][0][1];
float beta = result[1][i][0][2];
float sx = result[1][i][0][3];
float sy = result[1][i][0][4];
std::string name = result[1][i][1][2];
float score = result[1][i][1][1];
std::ostringstream message;
if (score > 0.6)
message << name;
else
message << "Unknown";
m_message.push_back( message.str() );
m_scores.push_back(score);
// sizeX / sizeY are the face size in relation to the image
float h = m_image_height * sx;
float w = m_image_width * sy;
// Center of face into the image
float x = m_image_width / 2 - m_image_width * alpha;
float y = m_image_height / 2 + m_image_height * beta;
vpImagePoint cog(x,y);
double dist = vpImagePoint::distance(m_previuos_cog,cog);
if (dist< min_dist)
{
closest_cog = cog;
index_closest_cog = i;
min_dist = dist;
}
std::vector<vpImagePoint> polygon;
double x_corner = x - h/2;
double y_corner = y - w/2;
polygon.push_back(vpImagePoint(y_corner , x_corner ));
polygon.push_back(vpImagePoint(y_corner+w, x_corner ));
polygon.push_back(vpImagePoint(y_corner+w, x_corner+h));
polygon.push_back(vpImagePoint(y_corner , x_corner+h));
m_polygon.push_back(polygon);
m_nb_objects ++;
}
if (index_closest_cog !=0)
std::swap(m_polygon[0], m_polygon[index_closest_cog]);
m_previuos_cog = closest_cog;
}
return target_found;
}
示例5: run
void NaoqiJointStates::run()
{
ros::Rate r(m_rate);
ros::Time stamp1;
ros::Time stamp2;
ros::Time stamp;
std::vector<float> odomData;
float odomX, odomY, odomZ, odomWX, odomWY, odomWZ;
std::vector<float> memData;
std::vector<float> positionData;
ROS_INFO("Staring main loop. ros::ok() is %d nh.ok() is %d",ros::ok(),m_nh.ok());
while(ros::ok() )
{
r.sleep();
ros::spinOnce();
stamp1 = ros::Time::now();
try
{
memData = m_memoryProxy->getListData(m_dataNamesList);
// {SPACE_TORSO = 0, SPACE_WORLD = 1, SPACE_NAO = 2}. (second argument)
odomData = m_motionProxy->getPosition("Torso", 1, true);
positionData = m_motionProxy->getAngles("Body", true);
}
catch (const AL::ALError & e)
{
ROS_ERROR( "Error accessing ALMemory, exiting...");
ROS_ERROR( "%s", e.what() );
//ros.signal_shutdown("No NaoQI available anymore");
}
stamp2 = ros::Time::now();
//ROS_DEBUG("dt is %f",(stamp2-stamp1).toSec()); % dt is typically around 1/1000 sec
// TODO: Something smarter than this..
stamp = stamp1 + ros::Duration((stamp2-stamp1).toSec()/2.0);
/******************************************************************
* IMU
*****************************************************************/
if (memData.size() != m_dataNamesList.getSize())
{
ROS_ERROR("memData length %zu does not match expected length %u",memData.size(),m_dataNamesList.getSize() );
continue;
}
// IMU data:
m_torsoIMU.header.stamp = stamp;
float angleX = memData[1];
float angleY = memData[2];
float angleZ = memData[3];
float gyroX = memData[4];
float gyroY = memData[5];
float gyroZ = memData[6];
float accX = memData[7];
float accY = memData[8];
float accZ = memData[9];
m_torsoIMU.orientation = tf::createQuaternionMsgFromRollPitchYaw(
angleX,
angleY,
angleZ); // yaw currently always 0
m_torsoIMU.angular_velocity.x = gyroX;
m_torsoIMU.angular_velocity.y = gyroY;
m_torsoIMU.angular_velocity.z = gyroZ; // currently always 0
m_torsoIMU.linear_acceleration.x = accX;
m_torsoIMU.linear_acceleration.y = accY;
m_torsoIMU.linear_acceleration.z = accZ;
// covariances unknown
// cf http://www.ros.org/doc/api/sensor_msgs/html/msg/Imu.html
m_torsoIMU.orientation_covariance[0] = -1;
m_torsoIMU.angular_velocity_covariance[0] = -1;
m_torsoIMU.linear_acceleration_covariance[0] = -1;
m_torsoIMUPub.publish(m_torsoIMU);
/******************************************************************
* Joint state
*****************************************************************/
m_jointState.header.stamp = stamp;
m_jointState.header.frame_id = m_baseFrameId;
m_jointState.position.resize(positionData.size());
for(unsigned i = 0; i<positionData.size(); ++i)
{
m_jointState.position[i] = positionData[i];
}
// simulated model misses some joints, we need to fill:
if (m_jointState.position.size() == 22)
{
m_jointState.position.insert(m_jointState.position.begin()+6,0.0);
m_jointState.position.insert(m_jointState.position.begin()+7,0.0);
m_jointState.position.push_back(0.0);
m_jointState.position.push_back(0.0);
}
//.........这里部分代码省略.........
示例6: UpdateList
void WifiManager::UpdateList()
{
// reload config
ParamEntry::Reload();
std::string serviceOff;
std::string serviceOn;
#if !WIFI_LOCAL_TEST
GetConnectionProxy().scan();
AL::ALValue serviceList = GetConnectionProxy().services();
// Log() << serviceList << std::endl;
#else // !LOCAL_TEST
AL::ALValue serviceList;
#endif // !LOCAL_TEST
_services.clear();
for (int i = 0; i < serviceList.getSize(); i++)
{
// Log() << "item[" << i << "]: " << serviceList[i] << std::endl;
std::map<std::string, std::string> details;
for (int j = 0; j < serviceList[i].getSize(); j++)
{
//Log() << " -- " << serviceList[i][j] << std::endl;
std::string name = serviceList[i][j][0];
std::string val;
if (serviceList[i][j][1].isString())
val = (std::string) serviceList[i][j][1];
else
val = serviceList[i][j][1].toString();
details[name] = val;
}
/*for (auto& item : details)
{
Log() << item.first << ": " << item.second << std::endl;
}*/
WifiService service;
service._id = details["ServiceId"];
service._name = details["Name"];
service._state = WifiStateUtils::StringToWifiState(details["State"]);
service.FindConfig();
_services.push_back(service);
if (service._knownConfig && service._knownConfig->_default && _selectedSSID.empty())
_selectedSSID = service._name;
}
#if WIFI_LOCAL_TEST
WifiService service;
service._id = "whatever";
service._name = "YETTI";
service._state = WifiStateUtils::StringToWifiState("Idle");
service.FindConfig();
_services.push_back(service);
if (service._knownConfig && service._knownConfig->_default && _selectedSSID.empty())
_selectedSSID = service._name;
#endif // WIFI_LOCAL_TEST
}
示例7: main
//.........这里部分代码省略.........
move_base_prev = move_base;
if (face_found) {
std::ostringstream text;
text << "Found " << face_tracker.getNbObjects() << " face(s)";
vpDisplay::displayText(I, 10, 10, text.str(), vpColor::red);
for(size_t i=0; i < face_tracker.getNbObjects(); i++) {
vpRect bbox = face_tracker.getBBox(i);
if (i == 0)
vpDisplay::displayRectangle(I, bbox, vpColor::red, false, 2);
else
vpDisplay::displayRectangle(I, bbox, vpColor::green, false, 1);
vpDisplay::displayText(I, (int)bbox.getTop()-10, (int)bbox.getLeft(), face_tracker.getMessage(i) , vpColor::red);
}
led_proxy.post.fadeRGB("FaceLeds","blue",0.1);
double u = face_tracker.getCog(0).get_u();
double v = face_tracker.getCog(0).get_v();
if (u<= g.getWidth() && v <= g.getHeight())
head_cog_cur.set_uv(u,v);
vpRect bbox = face_tracker.getBBox(0);
std::string name = face_tracker.getMessage(0);
//std::cout << "Loop time face print " << vpTime::measureTimeMs() - t << " ms" << std::endl;
}
AL::ALValue result = m_memProxy.getData("PeoplePerception/VisiblePeopleList");
//std::cout << "Loop time get Data PeoplePerception " << vpTime::measureTimeMs() - t << " ms" << std::endl;
person_found = false;
if (result.getSize() > 0)
{
AL::ALValue info = m_memProxy.getData("PeoplePerception/PeopleDetected");
int num_people = info[1].getSize();
std::ostringstream text;
text << "Found " << num_people << " person(s)";
vpDisplay::displayText(I, 10, 10, text.str(), vpColor::red);
person_found = true;
if (face_found) // Try to find the match between two detection
{
vpImagePoint cog_face;
double dist_min = 1000;
unsigned int index_person = 0;
for (unsigned int i = 0; i < num_people; i++)
{
float alpha = info[1][i][2];
float beta = info[1][i][3];
//Z = Zd;
// Centre of face into the image
float x = g.getWidth()/2 - g.getWidth() * beta;
float y = g.getHeight()/2 + g.getHeight() * alpha;
cog_face.set_uv(x,y);
dist = vpImagePoint::distance(cog_face, head_cog_cur);
if (dist < dist_min)
{
dist_min = dist;
best_cog_face_peoplep = cog_face;
index_person = i;
示例8: readSensors
/**
* The method reads all sensors. It also detects if the chest button was pressed
* for at least three seconds. In that case, it shuts down the robot.
*/
void readSensors()
{
// get new sensor values and copy them to the shared memory block
try
{
// copy sensor values into the shared memory block
int writingSensors = 0;
if(writingSensors == data->newestSensors)
++writingSensors;
if(writingSensors == data->readingSensors)
if(++writingSensors == data->newestSensors)
++writingSensors;
assert(writingSensors != data->newestSensors);
assert(writingSensors != data->readingSensors);
float* sensors = data->sensors[writingSensors];
for(int i = 0; i < lbhNumOfSensorIds; ++i)
sensors[i] = *sensorPtrs[i];
AL::ALValue value = memory->getData("GameCtrl/RoboCupGameControlData");
if(value.isBinary() && value.getSize() == sizeof(RoboCup::RoboCupGameControlData))
memcpy(&data->gameControlData[writingSensors], value, sizeof(RoboCup::RoboCupGameControlData));
data->newestSensors = writingSensors;
// detect shutdown request via chest-button
if(*sensorPtrs[chestButtonSensor] == 0.f)
startPressedTime = dcmTime;
else if(state != shuttingDown && startPressedTime && dcmTime - startPressedTime > 3000)
{
if(*sensorPtrs[rBumperRightSensor] != 0.f || *sensorPtrs[rBumperLeftSensor] != 0.f ||
*sensorPtrs[lBumperRightSensor] != 0.f || *sensorPtrs[lBumperLeftSensor] != 0.f)
(void) !system("( /home/nao/bin/bhumand stop && sudo shutdown -r now ) &");
else
(void) !system("( /home/nao/bin/bhumand stop && sudo shutdown -h now ) &");
state = preShuttingDown;
}
}
catch(AL::ALError& e)
{
fprintf(stderr, "libbhuman: %s\n", e.toString().c_str());
}
// raise the semaphore
if(sem != SEM_FAILED)
{
int sval;
if(sem_getvalue(sem, &sval) == 0)
{
if(sval < 1)
{
sem_post(sem);
frameDrops = 0;
}
else
{
if(frameDrops == 0)
fprintf(stderr, "libbhuman: dropped sensor data.\n");
++frameDrops;
}
}
}
}
示例9: main
/*!
Connect to Romeo robot, grab, display images using ViSP and start face detection with Okao library running on the robot.
By default, this example connect to a robot with ip address: 198.18.0.1.
*/
int main(int argc, const char* argv[])
{
try
{
std::string opt_ip = "198.18.0.1";;
if (argc == 3) {
if (std::string(argv[1]) == "--ip")
opt_ip = argv[2];
}
vpNaoqiGrabber g;
if (! opt_ip.empty())
g.setRobotIp(opt_ip);
g.setCamera(0);
g.open();
vpImage<unsigned char> I(g.getHeight(), g.getWidth());
vpDisplayX d(I);
vpDisplay::setTitle(I, "ViSP viewer");
// Open Proxy for the speech
AL::ALTextToSpeechProxy tts(opt_ip, 9559);
tts.setLanguage("English");
std::string phraseToSay = "Hi!";
// int id = tts.post.say(phraseToSay);
// tts.wait(id,2000);
// Open Face detection proxy
AL::ALFaceDetectionProxy df(opt_ip, 9559);
// Start the face recognition engine
const int period = 1;
df.subscribe("Face", period, 0.0);
AL::ALMemoryProxy memProxy(opt_ip, 9559);
float mImageHeight = g.getHeight();
float mImageWidth = g.getWidth();
std::vector<std::string> names;
while (1)
{
g.acquire(I);
vpDisplay::display(I);
AL::ALValue result = memProxy.getData("FaceDetected");
if (result.getSize() >=2)
{
//std::cout << "face" << std::endl;
AL::ALValue info_face_array = result[1];
for (unsigned int i = 0; i < info_face_array.getSize()-1; i++ )
{
// AL::ALValue info_face = info_face_array[i];
//Extract face info
//AL::ALValue shape_face =info_face[0];
//std::cout << "alpha "<< shape_face[1] <<". Beta:" << shape_face[1] << std::endl;
// Face Detected [1]/ First face [0]/ Shape Info [0]/ Alpha [1]
float alpha = result[1][i][0][1];
float beta = result[1][i][0][2];
float sx = result[1][i][0][3];
float sy = result[1][i][0][4];
std::string name = result[1][i][1][2];
float score = result[1][i][1][1];
// sizeX / sizeY are the face size in relation to the image
float sizeX = mImageHeight * sx;
float sizeY = mImageWidth * sy;
// Centre of face into the image
float x = mImageWidth / 2 - mImageWidth * alpha;
float y = mImageHeight / 2 + mImageHeight * beta;
vpDisplay::displayCross(I, y, x, 10, vpColor::red);
vpDisplay::displayRectangle(I,y,x,0.0,sizeX,sizeY,vpColor::cyan,1);
std::cout << i << "- size: " << sizeX*sizeY << std::endl;
//.........这里部分代码省略.........
示例10: processFaces
void InteractionMonitor::processFaces(const AL::ALValue &faces, map<string, Human>& humans) {
try {
/** Check that there are faces effectively detected. */
if (faces.getSize() < 2 ) {
if (facesCount != 0) {
ROS_INFO("No face detected");
humanBuffer = NB_VIEWS_BEFORE_LEARNING;
facesCount = 0;
}
return;
}
/** Check the number of faces from the FaceInfo field, and check that it has
* changed from the last event.*/
if (faces[1].getSize() - 1 != facesCount) {
ROS_INFO("%d face(s) detected.", faces[1].getSize() - 1);
/** Update the current number of detected faces. */
facesCount = faces[1].getSize() - 1;
}
}
catch (const AL::ALError& e) {
ROS_ERROR(e.what());
}
for (int i = 0; i < facesCount; ++i) {
int naoqiFaceId = faces[1][i][1][0];
float confidence = faces[1][i][1][1];
// Face > [FaceInfo] > FaceInfo > ShapeInfo > yaw
float yaw = faces[1][i][0][1];
// Face > [FaceInfo] > FaceInfo > ShapeInfo > pitch
float pitch = faces[1][i][0][2];
ROS_INFO("Face (id: %d) confidence:%.2f yaw: %.2f, pitch: %.2f", naoqiFaceId, confidence, yaw, pitch);
//ROS_INFO("Face (id: %d) reco confidence: %.2f", naoqiFaceId, confidence);
//ROS_INFO("Time_Filtered_Reco_Info: %s", faces[1][i].toString().c_str());
int candidateId = facesCloseTo(yaw, pitch);
if (naoqiFaceId == -1 && candidateId == -1) // seen unknown new face
{
if (humanBuffer > 0) {
humanBuffer--;
}
else {
humanBuffer = NB_VIEWS_BEFORE_LEARNING;
char faceId[6];
gen_random(faceId, 5);
ROS_INFO("Unknown face (confidence: %.2f). Learning it as <%s>", confidence, faceId);
if(!m_faceProxy->learnFace(faceId))
{
ROS_ERROR("Could not learn the new face!");
}
}
}
else { // face recognized!
humanBuffer = NB_VIEWS_BEFORE_LEARNING;
// too close to an existing face? re-use the existing face!
if (candidateId != -1) {
naoqiFaceId = candidateId;
}
else {
assert(naoqiFaceId != -1);
string label = faces[1][i][1][2];
id2label[naoqiFaceId] = label;
}
string label = id2label[naoqiFaceId];
// save the yaw,pitch pose of the recognized face, to
// prevent jitter at next round of detections
m_lastSeenHumans[naoqiFaceId] = make_pair(yaw, pitch);
humans[label] = makeHuman(label, yaw, pitch);
}
}
}