Пример #1
0
/*!
 *
 */
static void cvTrackBarEvents(int ,void*)
{
  if (iThresParam1<3)
    iThresParam1=3;
  if (iThresParam1%2!=1)
    iThresParam1++;
  if (dThresParam2<1)
    dThresParam2=1;

  dThresParam1=iThresParam1;
  dThresParam2=iThresParam2;
  boardDetector.getMarkerDetector().setThresholdParams(dThresParam1,dThresParam2);

  //recompute
  //Detection of the board
  float probDetect=boardDetector.detect( inpImg);
  inpImg.copyTo(inpImgCpy);
  if (params.isValid() && probDetect>0.2)
    aruco::CvDrawingUtils::draw3dAxis(inpImgCpy,boardDetector.getDetectedBoard(),params);


  cv::imshow("in",inpImgCpy);
  cv::imshow("thres",boardDetector.getMarkerDetector().getThresholdedImage());
}
Пример #2
0
/*!
 *
 */
int main(int argc,char **argv)
{
  readArguments(argc,argv);

  aruco::BoardConfiguration boardConf;
  boardConf.readFromFile(boC->sval[0]);

  cv::VideoCapture vcapture;

  //read from camera or from  file
  if (strcmp(inp->sval[0], "live")==0)
  {
    vcapture.open(0);
    vcapture.set(CV_CAP_PROP_FRAME_WIDTH,  wid->ival[0]);
    vcapture.set(CV_CAP_PROP_FRAME_HEIGHT, hei->ival[0]);
    int val = CV_FOURCC('M', 'P', 'E', 'G');
    vcapture.set(CV_CAP_PROP_FOURCC, val);
  }
  else
    vcapture.open(inp->sval[0]);

  //check video is open
  if (!vcapture.isOpened())
  {
    std::cerr<<"Could not open video"<<std::endl;
    return -1;
  }

  //read first image to get the dimensions
  vcapture>>inpImg;

  //Open outputvideo
  cv::VideoWriter vWriter;
  if (out->count)
    vWriter.open(out->sval[0], CV_FOURCC('M','J','P','G'), fps->ival[0], inpImg.size());

  //read camera parameters if passed
  if (intr->count)
  {
    params.readFromXMLFile(intr->sval[0]);
    params.resize(inpImg.size());
  }

  //Create gui
  cv::namedWindow("thres", CV_GUI_NORMAL | CV_WINDOW_AUTOSIZE);
  cv::namedWindow("in", CV_GUI_NORMAL | CV_WINDOW_AUTOSIZE);
  cvMoveWindow("thres", 0, 0);
  cvMoveWindow("in", inpImg.cols + 5, 0);
  boardDetector.setParams(boardConf,params,msiz->dval[0]);
  boardDetector.getMarkerDetector().getThresholdParams( dThresParam1,dThresParam2);
//  boardDetector.getMarkerDetector().enableErosion(true);//for chessboards
  iThresParam1=dThresParam1;
  iThresParam2=dThresParam2;
  cv::createTrackbar("ThresParam1", "in",&iThresParam1, 13, cvTrackBarEvents);
  cv::createTrackbar("ThresParam2", "in",&iThresParam2, 13, cvTrackBarEvents);
  int index=0;

  ///////////////
  // Main Lopp //
  ///////////////
  while(appRunnin)
  {
    inpImg.copyTo(inpImgCpy);
    index++;                                    //number of images captured
    double tick = static_cast<double>(cv::getTickCount());//for checking the speed
    float probDetect=boardDetector.detect(inpImg); //Detection of the board
    tick=(static_cast<double>(cv::getTickCount())-tick)/cv::getTickFrequency();
    std::cout<<"Time detection="<<1000*tick<<" milliseconds"<<std::endl;
    //print marker borders
    for (unsigned int i=0; i<boardDetector.getDetectedMarkers().size(); i++)
      boardDetector.getDetectedMarkers()[i].draw(inpImgCpy,cv::Scalar(0,0,255),1);

    //print board
    if (params.isValid())
    {
      if ( probDetect>thre->dval[0])
      {
        aruco::CvDrawingUtils::draw3dAxis( inpImgCpy,boardDetector.getDetectedBoard(),params);
      }
    }
    //DONE! Easy, right?

    //show input with augmented information and the thresholded image
    cv::imshow("in",inpImgCpy);
    cv::imshow("thres",boardDetector.getMarkerDetector().getThresholdedImage());

    // write to video if desired
    if (out->count)
    {
      //create a beautiful composed image showing the thresholded
      //first create a small version of the thresholded image
      cv::Mat smallThres;
      cv::resize(boardDetector.getMarkerDetector().getThresholdedImage(),smallThres,
                 cv::Size(inpImgCpy.cols/3,inpImgCpy.rows/3));
      cv::Mat small3C;
      cv::cvtColor(smallThres,small3C,CV_GRAY2BGR);
      cv::Mat roi=inpImgCpy(cv::Rect(0,0,inpImgCpy.cols/3,inpImgCpy.rows/3));
      small3C.copyTo(roi);
      vWriter<<inpImgCpy;
    }

    processKey(cv::waitKey(waitTime));//wait for key to be pressed
    appRunnin &= vcapture.grab();
    vcapture.retrieve(inpImg);
  }

  arg_freetable(argtable,sizeof(argtable)/sizeof(argtable[0]));
  return EXIT_SUCCESS;
}
int main(int argc, char** argv)
{
    
    /// READ PARAMETERS
    if(!readParameters(argc, argv))
    return false;
    
    /// CREATE UNDISTORTED CAMERA PARAMS
    CameraParamsUnd=CameraParams;
    CameraParamsUnd.Distorsion=cv::Mat::zeros(4,1,CV_32F);
    cout<<" REATE UNDISTORTED CAMERA PARAMS "<<endl;
    
    /// SET BOARD DETECTOR PARAMETERS
    TheBoardDetector.setParams(TheBoardConfig,CameraParamsUnd,TheMarkerSize);
    
    /// CAPTURE FIRST FRAME
    TheVideoCapturer.grab();
    TheVideoCapturer.retrieve ( TheInputImage );
    cv::undistort(TheInputImage,TheInputImageUnd,CameraParams.CameraMatrix,CameraParams.Distorsion);
    cout<<" CAPTURE FIRST FRAME "<<endl;
    /// INIT OGRE
    initOgreAR(CameraParamsUnd, TheInputImageUnd.ptr<uchar>(0));
    cout<<" OGRE initiated "<<endl;
    while (TheVideoCapturer.grab())
    {
        
        /// READ AND UNDISTORT IMAGE
        TheVideoCapturer.retrieve ( TheInputImage );
        cv::undistort(TheInputImage,TheInputImageUnd,CameraParams.CameraMatrix,CameraParams.Distorsion);
        
        /// DETECT BOARD
        float probDetect = TheBoardDetector.detect(TheInputImageUnd);
        cout<<" detection: "<<probDetect<<endl;
        /// UPDATE BACKGROUND IMAGE
        mTexture->getBuffer()->blitFromMemory(mPixelBox);
        
        /// UPDATE SCENE
        if ( probDetect>0.2) ogreNode->setVisible(true);
        else ogreNode->setVisible(false);
        
        // set node pose
        double position[3], orientation[4];
        TheBoardDetector.getDetectedBoard().OgreGetPoseParameters(position, orientation);
        ogreNode->setPosition( position[0], position[1], position[2]  );
        ogreNode->setOrientation( orientation[0], orientation[1], orientation[2], orientation[3]  );
        
        // Update animation
        double deltaTime = 1.2*root->getTimer()->getMilliseconds()/1000.;
        baseAnim->addTime(deltaTime);
        topAnim->addTime(deltaTime);
        root->getTimer()->reset();
        
        /// RENDER FRAME
        if(root->renderOneFrame() == false) break;
        Ogre::WindowEventUtilities::messagePump();
        
        /// KEYBOARD INPUT
        keyboard->capture();
        if (keyboard->isKeyDown(OIS::KC_ESCAPE)) break;
        
        
    }
    
    im->destroyInputObject(keyboard);
    im->destroyInputSystem(im);
    im = 0;
    
    delete root;
    return 0;
}