예제 #1
0
void showAnCalChrRes::on_pbSaveScene_clicked()
{
    //Identify filename
    //..
    if(ui->txtQuadFilename->text().trimmed().isEmpty()){
        funcShowMsg("Lack","Type a file-name");
        ui->txtQuadFilename->setFocus();
        return (void)NULL;
    }
    //FileName
    //..
    QString fileName;
    fileName.append("./settings/Calib/images/");
    fileName.append(ui->txtQuadFilename->text());
    fileName.append(".png");
    //Save
    //..
    //Remove if exists
    QFile prevImg(fileName);
    if(prevImg.exists()){
        prevImg.remove();
    }
    prevImg.close();
    //Save Graphicsview's scene
    QPixmap pixMap = QPixmap::grabWidget(ui->canvasCroped);
    if(pixMap.save(fileName)){
        funcShowMsg(" ","Image saved successfully");
    }else{
        funcShowMsg("ERROR","Saving image");
    }

}
예제 #2
0
void MainWindow::keyPressEvent(QKeyEvent * qkey)
{
    QString file1,file2;
    switch(qkey->key())
    {
    case Qt::Key_Right:
     case Qt::Key_D:
         nextImg();
         break;
     case Qt::Key_Left:
     case Qt::Key_A:
         prevImg();
         break;
    case Qt::Key_S:

        file1 = imgdir.buildPath(
                    program_settings.retrive(DIR1_SETT),
                    imgdir.fileList.at(index).toStdString()).c_str();
        file2 = imgdir.buildPath(
                    program_settings.retrive(DIR2_SETT),
                    imgdir.fileList.at(index).toStdString()).c_str();

        dbg << file1.toStdString() << std::endl;
        dbg << file2.toStdString() << std::endl;
        imgdir.copyImg(file1,file2);
        this->setWindowTitle(this->windowTitle().append(" (COPIED)"));
        break;
    case Qt::Key_W:

        file1 = imgdir.buildPath(
                    program_settings.retrive(DIR1_SETT),
                    imgdir.fileList.at(index).toStdString()).c_str();
        file2 = imgdir.buildPath(
                    program_settings.retrive(DIR2_SETT),
                    imgdir.fileList.at(index).toStdString()).c_str();

        dbg << file1.toStdString() << std::endl;
        dbg << file2.toStdString() << std::endl;
        imgdir.moveImg(file1,file2);
        imgdir.fileList.removeAt(index--);
        nextImg();
        break;
    case Qt::Key_Space:
        on_slideShowStart_clicked();
        break;    
    default:
        break;
    }
    coutdebug();
}
예제 #3
0
ImageViewer::ImageViewer(QWidget *parent):
	QDockWidget(parent),
	image(NULL),
	dirp(NULL),
	inFile(NULL),
	imageCounter(0),
	playFlag(false)
{
	//! Initialize window attributes
	setWindowTitle("Image Viewer");
	setFixedSize(800,600);

	//! Initialize play button
	play = new QPushButton("Play",this);
	play->setGeometry(0,500,200,30);

	//! Initialize prev Button
	prev = new QPushButton("Previous",this);
	prev->setGeometry(200,500,200,30);

	//! Initialize next Button
	next = new QPushButton("Next",this);
	next->setGeometry(400,500,200,30);

	//! Open directory and initialize first image
	dirp = opendir("images");
	do{
		inFile = readdir(dirp);
	}while(inFile->d_name[0]=='.');
	for(int i=0;i<20;++i)
		nameBuffer[imageCounter][i] = inFile->d_name[i];
	curImage = imageCounter++;
	sprintf(imagePath,"images/%s",inFile->d_name);

	//! Initialize play timer 
	timer = new QTimer(this);
	QObject::connect(timer, SIGNAL(timeout()), this, SLOT(nextImg()));

	//! QLabel image used as the "frame" in the window, holding the image
	image = new QLabel("Dank Memes", this);
	image->setGeometry(0, 0, 800, 500);
	image->setPixmap(QPixmap(imagePath));
	
	//! Assign button functions
	QObject::connect(next, SIGNAL(clicked()), this, SLOT(nextImg()));
	QObject::connect(prev, SIGNAL(clicked()), this, SLOT(prevImg()));
	QObject::connect(play, SIGNAL(clicked()), this, SLOT(playImg()));
}
예제 #4
0
void MainWindow::on_prevButton_clicked()
{
    prevImg();
}
예제 #5
0
int main(int argc, char **argv)
{
  int res;

  try {
    socket.bind ("tcp://*:14444");
    s_sendmore (socket, "event");
        s_send (socket, "{type:\"up\"}");
  }
  catch (zmq::error_t e) {
    cerr << "Cannot bind to socket: " <<e.what() << endl;
    return -1;
  }

  //  printf("Kinect camera test\n");
  //
  //  int i;
  //  for (i=0; i<2048; i++) {
  //    float v = i/2048.0;
  //    v = powf(v, 3)* 6;
  //    t_gamma[i] = v*6*256;
  //  }
  //
  //  g_argc = argc;
  //  g_argv = argv;
  //
  //  //setup Freenect...
  //  if (freenect_init(&f_ctx, NULL) < 0) {
  //    printf("freenect_init() failed\n");
  //    return 1;
  //  }
  //
  //  freenect_set_log_level(f_ctx, FREENECT_LOG_ERROR);
  //
  //  int nr_devices = freenect_num_devices (f_ctx);
  //  printf ("Number of devices found: %d\n", nr_devices);
  //
  //  int user_device_number = 0;
  //  if (argc > 1)
  //    user_device_number = atoi(argv[1]);
  //
  //  if (nr_devices < 1)
  //    return 1;
  //
  //  if (freenect_open_device(f_ctx, &f_dev, user_device_number) < 0) {
  //    printf("Could not open device\n");
  //    return 1;
  //  }
  //
  //  freenect_set_tilt_degs(f_dev,freenect_angle);
  //  freenect_set_led(f_dev,LED_RED);
  //  freenect_set_depth_callback(f_dev, depth_cb);
  //  freenect_set_video_callback(f_dev, rgb_cb);
  //  freenect_set_video_format(f_dev, FREENECT_VIDEO_RGB);
  //  freenect_set_depth_format(f_dev, FREENECT_DEPTH_11BIT);
  //
  //  freenect_start_depth(f_dev);
  //  freenect_start_video(f_dev);

  initFreenect();

  //start the freenect thread to poll for events
  res = pthread_create(&ocv_thread, NULL, freenect_threadfunc, NULL);
  if (res) {
    printf("pthread_create failed\n");
    return 1;
  }

  Mat depthf;

  Mat frameMat(rgbMat);
  Mat blobMaskOutput(frameMat.size(),CV_8UC1),
  outC(frameMat.size(),CV_8UC3);
  Mat prevImg(frameMat.size(),CV_8UC1),
  nextImg(frameMat.size(),CV_8UC1),
  prevDepth(depthMat.size(),CV_8UC1);
  vector<Point2f> prevPts,nextPts;
  vector<uchar> statusv;
  vector<float> errv;
  Rect cursor(frameMat.cols/2,frameMat.rows/2,10,10);
  bool update_bg_model = true;
  int fr = 1;
  int register_ctr = 0,register_secondbloc_ctr = 0;
  bool registered = false;

  Point2i appear(-1,-1); double appearTS = -1;

  Point2i midBlob(-1,-1);
  Point2i lastMove(-1,-1);

  int hcr_ctr = -1;
  vector<int> hc_stack(20); int hc_stack_ptr = 0;

  while (!die) {
    fr++;

    //    imshow("rgb", rgbMat);
    pthread_mutex_lock(&buf_mutex);

    //Linear interpolation
    {
      Mat _tmp = (depthMat - 400.0);          //minimum observed value is ~440. so shift a bit
      _tmp.setTo(Scalar(2048), depthMat > ((!registered) ? 700.0 : 750.0));   //cut off at 600 to create a "box" where the user interacts
      _tmp.convertTo(depthf, CV_8UC1, 255.0/1648.0);  //values are 0-2048 (11bit), account for -400 = 1648
    }

    {
      Mat _tmp;
      depthMat.convertTo(_tmp, CV_8UC1, 255.0/2048.0);
      cvtColor(_tmp, outC, CV_GRAY2BGR);
    }

    pthread_mutex_unlock(&buf_mutex);

    //    { //saving the frames to files for debug
    //      stringstream ss; ss << "depth_"<<fr<<".png";
    //      imwrite(ss.str(), depthf);
    //    }

    //Logarithm interpolation - try it!, It should be more "sensitive" for closer depths
    //    {
    //      Mat tmp,tmp1;
    //      depthMat.convertTo(tmp, CV_32FC1);
    //      log(tmp,tmp1);
    //      tmp1.convertTo(depthf, CV_8UC1, 255.0/7.6246189861593985);
    //    }
    //    imshow("depth",depthf);


    Mat blobMaskInput = depthf < 255; //anything not white is "real" depth
    vector<Point> ctr,ctr2;


    Scalar blb = refineSegments(Mat(),blobMaskInput,blobMaskOutput,ctr,ctr2,midBlob); //find contours in the foreground, choose biggest
    imshow("first", blobMaskOutput);
    /////// blb :
    //blb[0] = x, blb[1] = y, blb[2] = 1st blob size, blb[3] = 2nd blob size.

    //    uint mode_counters[3] = {0};

    if(blb[0]>=0 && blb[2] > 500) { //1st blob detected, and is big enough
      //cvtColor(depthf, outC, CV_GRAY2BGR);

      //closest point to the camera
      Point minLoc; double minval,maxval;
      minMaxLoc(depthf, &minval, &maxval, &minLoc, NULL, blobMaskInput);
      circle(outC, minLoc, 5, Scalar(0,255,0), 3);

      Scalar mn,stdv;
      meanStdDev(depthf,mn,stdv,blobMaskInput);

      //cout << "min: " << minval << ", max: " << maxval << ", mean: " << mn[0] << endl;

      blobMaskInput = depthf < (mn[0] + stdv[0]*.5);

      blb = refineSegments(Mat(),blobMaskInput,blobMaskOutput,ctr,ctr2,midBlob);

      imshow("second", blobMaskOutput);

      if(blb[0] >= 0 && blb[2] > 300) {
        //draw contour
        Scalar color(0,0,255);
        for (int idx=0; idx<ctr.size()-1; idx++)
          line(outC, ctr[idx], ctr[idx+1], color, 1);
        line(outC, ctr[ctr.size()-1], ctr[0], color, 1);

        if(ctr2.size() > 0) {
          Scalar color2(255,0,255);
          for (int idx=0; idx<ctr2.size()-1; idx++)
            line(outC, ctr2[idx], ctr2[idx+1], color2, 2);
          line(outC, ctr2[ctr2.size()-1], ctr2[0], color2, 2);
        }

        //draw "major axis"
        //      Vec4f _line;
        Mat curve(ctr);
        //      fitLine(curve, _line, CV_DIST_L2, 0, 0.01, 0.01);
        //      line(outC, Point(blb[0]-_line[0]*70,blb[1]-_line[1]*70),
        //            Point(blb[0]+_line[0]*70,blb[1]+_line[1]*70),
        //            Scalar(255,255,0), 1);

        //blob center
        circle(outC, Point(blb[0],blb[1]), 50, Scalar(255,0,0), 3);


        //      cout << "min depth " << minval << endl;

        register_ctr = MIN((register_ctr + 1),60);

        if(blb[3] > 5000)
          register_secondbloc_ctr = MIN((register_secondbloc_ctr + 1),60);

        if (register_ctr > 30 && !registered) {
          registered = true;
          appear.x = -1;
          update_bg_model = false;
          lastMove.x = blb[0]; lastMove.y = blb[1];

          cout << "blob size " << blb[2] << endl;

          if(register_secondbloc_ctr < 30) {
            if(blb[2] > 10000) {
              cout << "register panner" << endl;
              send_event("Register", "\"mode\":\"openhand\"");
            } else {
              cout << "register pointer" << endl;
              send_event("Register", "\"mode\":\"theforce\"");
            }
          } else {
            cout << "register tab swithcer" << endl;
            send_event("Register", "\"mode\":\"twohands\"");
          }
        }

        if(registered) {
          stringstream ss;
          ss  << "\"x\":"  << (int)floor(blb[0]*100.0/640.0)
            << ",\"y\":" << (int)floor(blb[1]*100.0/480.0)
            << ",\"z\":" << (int)(mn[0] * 2.0);
          //cout << "move: " << ss.str() << endl;
          send_event("Move", ss.str());

          //---------------------- fist detection ---------------------
          //calc laplacian of curve
          vector<Point> approxCurve;  //approximate curve
          approxPolyDP(curve, approxCurve, 10.0, true);
          Mat approxCurveM(approxCurve);

          Mat curve_lap;
          calc_laplacian(approxCurveM, curve_lap);  //calc laplacian

          hcr_ctr = 0;
          for (int i=0; i<approxCurve.size(); i++) {
            double n = norm(((Point2d*)(curve_lap.data))[i]);
            if (n > 10.0) {
              //high curvature point
              circle(outC, approxCurve[i], 3, Scalar(50,155,255), 2);
              hcr_ctr++;
            }
          }

          hc_stack.at(hc_stack_ptr) = hcr_ctr;
          hc_stack_ptr = (hc_stack_ptr + 1) % hc_stack.size();

          Scalar _avg = mean(Mat(hc_stack));
          if (abs(_avg[0] - (double)hcr_ctr) > 5.0) { //a big change in curvature = hand fisted/opened?
            cout << "Hand click!" << endl;
            send_event("HandClick", "");
          }

          if (mode_state == MODE_NONE) {

          }

          //        imshow("out",out);
          //doHist(depthf,out);

          { //some debug on screen..
            stringstream ss; ss << "high curve pts " << hcr_ctr << ", avg " << _avg[0];
            putText(outC, ss.str(), Point(50,50), CV_FONT_HERSHEY_PLAIN, 2.0,Scalar(0,0,255), 2);
          }
        } else {
          //not registered, look for gestures
          if(appear.x<0) {
            //first appearence of blob
            appear = midBlob;
            //          update_bg_model = false;
            appearTS = getTickCount();
            cout << "appear ("<<appearTS<<") " << appear.x << "," << appear.y << endl;
          } else {
            //blob was seen before, how much time passed
            double timediff = ((double)getTickCount()-appearTS)/getTickFrequency();
            if (timediff > .2 && timediff < 1.0) {
              //enough time passed from appearence
              line(outC, appear, Point(blb[0],blb[1]), Scalar(0,0,255), 3);
              if (appear.x - blb[0] > 100) {
                cout << "right"<<endl; appear.x = -1;
                send_event("SwipeRight", "");
                update_bg_model = true;
                register_ctr = 0;
              } else if (appear.x - blb[0] < -100) {
                cout << "left" <<endl; appear.x = -1;
                send_event("SwipeLeft", "");
                update_bg_model = true;
                register_ctr = 0;
              } else if (appear.y - blb[1] > 100) {
                cout << "up" << endl; appear.x = -1;
                send_event("SwipeUp", "");
                update_bg_model = true;
                register_ctr = 0;
              } else if (appear.y - blb[1] < -100) {
                cout << "down" << endl; appear.x = -1;
                send_event("SwipeDown", "");
                update_bg_model = true;
                register_ctr = 0;
              }
            }
            if(timediff >= 1.0) {
              cout << "a ghost..."<<endl;
              update_bg_model = true;
              //a second passed from appearence - reset 1st appear
              appear.x = -1;
              appearTS = -1;
              midBlob.x = midBlob.y = -1;
            }
          }
        }
        send_image(outC);
      }
    } else {
      send_image(depthf);
      register_ctr = MAX((register_ctr - 1),0);
      register_secondbloc_ctr = MAX((register_secondbloc_ctr - 1),0);
    }
    imshow("blob",outC);

    if (register_ctr <= 15 && registered) {
      midBlob.x = midBlob.y = -1;
      registered = false;
      mode_state = MODE_NONE;
      update_bg_model = true;
      cout << "unregister" << endl;
      send_event("Unregister", "");
    }

        char k = cvWaitKey(5);
        if( k == 27 ) break;
        if( k == ' ' )
            update_bg_model = !update_bg_model;
    if (k=='s') {
      cout << "send test event" << endl;
      send_event("TestEvent", "");
    }
  }

  printf("-- done!\n");

  pthread_join(ocv_thread, NULL);
  pthread_exit(NULL);
  return 0;
}