Пример #1
0
	void mapFunction::goMap(int fd, rio_t client, int ID){
		pthread_mutex_lock(&mtx);
		char buf1[MAXLINE];
		int jobID=ID;
		int numBytes;
  		char * saveptr=NULL;
  		char * id1;
		char * id2;
		//char * id3;
		//Rio_readinitb( &client,fd);
  		numBytes = Rio_readlineb(&client, buf1, MAXLINE);
		if(numBytes<0) return;
		id1 = strtok_r(buf1, "*",&saveptr);
		int fileStartID=atoi(id1);
		id2 = strtok_r(NULL, "* \r\n",&saveptr);
		int fileEndID=atoi(id2);
		//id3 = strtok_r(NULL, "* \r\n",&saveptr);
		//jobID=atoi(id3);
		map<string,int> jobMap;
		for(int i=fileStartID;i<=fileEndID;i++){
			imageInfo myImage=getImage(i);
			//printf("%dfile name %s\n", i, myImage.name.data());
			if(circleDetect(myImage.myPic)==0) continue;
			else{
				printf("found %d %s\n",i, myImage.name.data());
				jobMap[myImage.name]=jobMap[myImage.name]+1;
			}
		}
		myMap[jobID]=jobMap;
		finished[jobID]=true;
		pthread_mutex_unlock(&mtx);
		//Close(fd);
	}
//捕获一张图像
void MeasureMarkersWindow::capture() {
  //先停止时钟
  mTimer->stop();

  static int COUNT = 0;
  COUNT++;
  QString name;
  name.sprintf("%d", COUNT);

  //先保存图像
  QString leftname = mMeasureFolder + "left_" + name;
  QString rightname = mMeasureFolder + "right_" + name;
  mLastLeft.save(leftname + ".jpg");
  mLastRight.save(rightname + ".jpg");
  mImgWidth = mLastLeft.width();
  mImgHeight = mLastLeft.height();

  //读取图像,计算角点
  cv::Mat li = cv::imread(leftname.toStdString() + ".jpg", CV_LOAD_IMAGE_UNCHANGED);
  cv::Mat ri = cv::imread(rightname.toStdString() + ".jpg", CV_LOAD_IMAGE_UNCHANGED);
  cv::Mat liGrey, riGrey;
  cv::cvtColor(li, liGrey, cv::COLOR_BGR2GRAY);
  cv::cvtColor(ri, riGrey, cv::COLOR_BGR2GRAY);

  std::vector<cv::Point2f> left_markers = circleDetect(liGrey);
  std::vector<cv::Point2f> right_markers = circleDetect(riGrey);

  for (int i = 0; i < left_markers.size(); i++)
    cv::circle(li, left_markers[i], 4, cv::Scalar(0, 0, 255), 3, 8, 0);
  for (int i = 0; i < right_markers.size(); i++)
    cv::circle(ri, right_markers[i], 4, cv::Scalar(0, 0, 255), 3, 8, 0);

  //保存绘制的角点图像
  cv::imwrite(leftname.toStdString() + ".bmp", li);
  cv::imwrite(rightname.toStdString() + ".bmp", ri);

  if (left_markers.size() == 2 && right_markers.size() == 2) {
    //先暂停摄像头
    preview();

    //记录当前图像
    mImgs.push_back(COUNT);

    //显示绘制角点的图像
    QImage lp = convertToQImage(li);
    QImage rp = convertToQImage(ri);
    mLeftCameraPixmap->setPixmap(QPixmap::fromImage(lp));
    mRightCameraPixmap->setPixmap(QPixmap::fromImage(rp));

    //提示找到角点
    mStatusBar->showMessage(QString::fromWCharArray(L"成功找到标记点"));

    int all = mImgs.size();
    QString ta;
    ta.sprintf(" %d/%d", all, all);
    mCaps->setText(ta);

    mSlider->setMaximum(mImgs.size());
    mSlider->setValue(mImgs.size());
    updateButtonState();
    return;
  } else {
    //删除保存的图像
    QFile::remove(leftname + ".jpg");
    QFile::remove(rightname + ".jpg");

    //计数回到为初始值
    COUNT--;

    //弹出对话框,提示没有找到角点
    mStatusBar->showMessage(QString::fromWCharArray(L"没有找到标记点"));
    QMessageBox::StandardButton btn2 = QMessageBox::warning(
      0,						//父窗口
      QString::fromWCharArray(L"没有找到标记点"),			//标题栏
      QString::fromWCharArray(L"在当前的图像中,没有找到对应的标记点"));		//文本内容

    //重新开始
    mTimer->start();
  }
}