-1

在c ++中重复时钟时重置窗口的问题

我试图用时间来重置时间,chrono。但是,代码执行时间在没有初始化的情况下继续增加。

你好,我是韩国技术学院的学生。使用翻译器。请原谅我说话很尴尬。

我正在设计一个程序,它使用 C++ OpenPose 库来衡量正确的 PC 用户税。基本上,我们已经完成了右肩或左肩歪斜时浮动弹窗提供反馈的功能。但是,我想在一秒钟后发出警报,而不是在错误位置发送反馈。

  1. 应该在不执行假设功能时测量时间,但是当用户坐在错误的位置时。时间将从执行 supose 函数的时间开始计算。如果同一个座位在错误的座位上保持 20 秒,则应该发生事件。

  2. 该事件会在 20 秒后发生,如果时间没有初始化,一旦识别为不正确的姿势就会发生。我想是因为什么时候。如果库从哪里中断,则以 0 代码结束。

一旦我解决了与时间相关的函数,我会问你一个问题,因为我很难完成这个程序。谢谢你。


while (!userWantsToExit)
        {
 // start frame

std::shared_ptr<std::vector<UserDatum>> datumProcessed;

  if (opWrapper.waitAndPop(datumProcessed))
  {

    userWantsToExit = userOutputClass.display(datumProcessed);
    userOutputClass.printKeypoints(datumProcessed);
....

//string to int

int subShoulder = stoi(rShoulderY) - stoi(lShoulderY);

//clac keypoint values for posedata

if (50 < subShoulder || -50 > subShoulder)
 {

  if (stoi(rShoulderY) < stoi(lShoulderY)) {

    clock_t t_start, t_end;
        int time;
    t_start = clock(); //start clock
    time = t_start / CLOCKS_PER_SEC;
    op::log(time);
    if (time > 20) {
      t_end = clock(); //end clock
      time = (int)(t_end - t_start) / CLOCKS_PER_SEC;
      cv::imshow("SUPOSE", imgLshoulderDown);
      std::string id = "hjw";
      std::string pose = "leftShoulder";
      httpRequestPose(id, pose);        
      }
    }
    else if (stoi(rShoulderY) > stoi(lShoulderY)) {
    clock_t t_start, t_end;
    int time;
    t_start = clock(); //start clock
    time = t_start / CLOCKS_PER_SEC;
    op::log(time);
    if (time > 20) {
      cv::imshow("SUPOSE", imgRshoulderDown);
      std::string id = "hjw";
      std::string pose = "rightShoulder";
      httpRequestPose(id, pose);

    }
    t_end = clock();
    time = (int)(t_end - t_start) / CLOCKS_PER_SEC;
     }
     else {
    clock_t t_start, t_end;
    int time;

    t_end = clock();
    time = (int)(t_end - t_start) / CLOCKS_PER_SEC;
     }
  }

 }


else {}

 //op::log("Processed datum could not be emplaced.", op::Priority::High, __LINE__, __FUNCTION__, __FILE__);

}

*图片

输入图片 1

输入图片 2

输入图片 3

进入图片 4

4

1 回答 1

0

老实说,我很难完全理解你的问题。然而,我是一名学生,英语并不好(即使是现在),我知道在谷歌翻译的段落上寻求帮助是多么困难。因此,我会尝试一下。

据我了解,如果肩膀向左倾斜超过 20 秒(与向右倾斜相同),您想触发警报。那是对的吗?

如果正确,我认为问题在于您将变量t_start保留在poseDetect函数中。这意味着每次检测到姿势时,t_start都是一个新姿势。值(t_end - t_start)始终为 0。您应该在该函数之外声明t_start并使用标志来检查它是否是第一次。我想用下面的伪代码建议

bool isLeftIncline = false;
clock_t startLeft=clock(); //get current time

void poseDetect()
{
    if (50 < subShoulder || -50 > subShoulder){
        if (stoi(rShoulderY) < stoi(lShoulderY)){ // should is inclined to the left 
            if(!isLeftIncline){ // the first time 
                startLeft=clock(); // get the starting time
                isLeftIncline=true;
                //trigger for the first time here
            }else {  // after the first time
                clock_t current=clock();
                int timeDiff=current-startLeft;
                if(timeDiff>20){ //after 20 second with same pose
                    // issue an alert
                }

                //or trigger alert every nearly 20 seconds 
                //if(timeDiff%20<3){
                    //trigger
                //}
            }

        }else {
            // the shoulder no longer inclines to the left
            // reset isLeftIncline time
            isLeftIncline = false;
        }

        // you can apply the same for the right incline here
    }

}
于 2019-05-29T14:05:44.237 回答