示例#1
0
void SuperGeometry2D::regionGrowing(unsigned short fromM, unsigned short toM,
    int seedX, int seedY, int offsetX, int offsetY,
    std::map<std::vector<int>, int>* tmp) {

  std::map<std::vector<int>, int> tmp2;
  bool firstCall = false;
  if (tmp == NULL) {
    tmp = &tmp2;
    firstCall = true;
  }

  if (getMaterial(seedX, seedY) == fromM) {
    std::vector<int> found;
    found.push_back(seedX);
    found.push_back(seedY);
    if (tmp->count(found) == 0) {
      (*tmp)[found] = 2;
      if (offsetX != 0) {
        regionGrowing(fromM, toM, seedX + 1, seedY, offsetX,
                      offsetY,  tmp);
        regionGrowing(fromM, toM, seedX - 1, seedY, offsetX,
                      offsetY,  tmp);
      }
      if (offsetY != 0) {
        regionGrowing(fromM, toM, seedX, seedY + 1,  offsetX,
                      offsetY, tmp);
        regionGrowing(fromM, toM, seedX, seedY - 1,  offsetX,
                      offsetY, tmp);
      }
    }
  }
  if (firstCall) {
    std::map<std::vector<int>, int>::iterator iter;
    for (iter = tmp->begin(); iter != tmp->end(); iter++) {
      setMaterial((iter->first)[0],(iter->first)[1],toM);
     }
  }
  return;
}
void TeamMarkerPerceptor::extractTeamMarkers(TeamMarkerSpots& teamMarkerSpots)
{
  typedef const RegionPercept::Region* R;

  unsigned start = SystemCall::getRealSystemTime();
  for(R region = theRegionPercept.regions, end = region + theRegionPercept.regionsCounter; region < end; ++region)
  {
    switch(region->color)
    {
    case ColorClasses::blue:
    case ColorClasses::robotBlue:
    case ColorClasses::red:
    {
      unsigned duration = SystemCall::getRealSystemTime() - start;
      if(duration > params.maxDuration)
      {
        DEBUG_RESPONSE("module:TeamMarkerPerceptor:time",
        {
          OUTPUT_WARNING("SKIPPED team marker perception (duration: " << duration << " ms)");
        });
        return;
      }

      TeamMarkerSpots::TeamMarkerSpot teamMarker;
      teamMarker.color = region->color;

      ABORTABLE_STEP(regionCheck(region), *region->childs[0], ColorClasses::red)
      ABORTABLE_STEP(regionGrowing(teamMarker), approxCog, ColorClasses::green)
      ABORTABLE_STEP(scanlineRegionArea(teamMarker), approxCog, ColorClasses::yellow)
      ABORTABLE_STEP(scanlineRegionPrincipalAxis(teamMarker), approxCog, ColorClasses::orange)

      polygonDebugDrawing(teamMarker);
      teamMarkerSpots.teamMarkers.push_back(teamMarker);

      break;
    }
示例#3
0
/**
    Fonction principale de traitement
*/
void modeStationnaire()
{
        // Declaration
    //Fps timeCounter;
    int  on = 1;
    pthread_t grabF;
    pthread_t grabB;
	int id_from, id_msg, ordre = 100;

    cvNamedWindow("T",CV_WINDOW_AUTOSIZE);
    std::cerr << std::endl << std::endl;

        // Lancement des threads
    if(captureCameraF!=NULL){
        pthread_create ( &grabF, NULL, grabCamF, NULL );
    }
    if(captureCameraB!=NULL){
        pthread_create ( &grabB, NULL, grabCamB, NULL );
    }

    string s;
        // Boucle principale
    while(on){
        cin >> s;
        parse(s,&id_from, &id_msg, &ordre);
        cout << -1 << '.' << id_msg << '.';
        //cout << id_from << id_msg << ordre;
        //scanf("%d.%d.%d",&id_from, &id_msg, &ordre);
        //fflush(stdin);

        //printf("-1.%d.[]",id_msg);

        // *****
        switch(ordre){

            // --- Identification ---
            case 0:{
                cout << 1 << '.' << "cam";
            break;}

            // --- Ping ---
            case 1:{
                cout << "Pong";
            break;}

            // --- ScanAvant ---
            case 64:{
                    pthread_mutex_lock (& mu);
                    imgBas=cvQueryFrame(captureCameraF);
                    pthread_mutex_unlock (& mu);

                    listFinal->iniPtr();
                    while(listFinal->getEle()!=NULL){
                        listFinal->getEle()->color=5;
                        listFinal->ptrSuiv();
                    }

                    binarisation();
                    regionGrowing();
                    listFinal = analyseListeRegion(listBeforeTrait, IMG_WIDTH, IMG_HEIGHT);
                    sendData(listFinal);

                    //afficheListeRegion(listFinal, imgBas);
                    //cvShowImage("T",imgBas);

                    cvWaitKey(10);
            break;}

            // --- ScanArriére ---
            case 65:{

                    pthread_mutex_lock (& mu);
                    imgBas=cvQueryFrame(captureCameraB);
                    pthread_mutex_unlock (& mu);

                    listFinal->iniPtr();
                    while(listFinal->getEle()!=NULL){
                        listFinal->getEle()->color=5;
                        listFinal->ptrSuiv();
                    }

                    binarisation();
                    regionGrowing();
                    listFinal = analyseListeRegion(listBeforeTrait, IMG_WIDTH, IMG_HEIGHT);
                    sendData(listFinal);


                    //afficheListeRegion(listFinal, imgBas);
                    //cvShowImage("T",imgBas);

                    cvWaitKey(10);
            break;}

#define SXL 20
            case 62:{

                for(int tmp=0; tmp<5; tmp++)
                {
                    pthread_mutex_lock (& mu);
                    imgBas=cvQueryFrame(captureCameraF);
                    pthread_mutex_unlock (& mu);

                    binarisation();
                    regionGrowing();

                    if(tmp==0){
                        listFinal = analyseListeRegion(listBeforeTrait, IMG_WIDTH, IMG_HEIGHT);
                        listFinal->iniPtr();
                        while(listFinal->getEle()!=NULL){
                            listFinal->getEle()->color=0;
                            listFinal->ptrSuiv();
                        }
                    }else{
                        listTmp = analyseListeRegion(listBeforeTrait, IMG_WIDTH, IMG_HEIGHT);
                        listFinal->iniPtr();
                        while(listFinal->getEle()!=NULL){
                            listTmp->iniPtr();
                            while(listTmp->getEle()!=NULL){

                                if
                                (
                                    listTmp->getEle()->Xprime - SXL < listFinal->getEle()->Xprime &&
                                    listTmp->getEle()->Xprime + SXL > listFinal->getEle()->Xprime &&
                                    listTmp->getEle()->Yprime - SXL < listFinal->getEle()->Yprime &&
                                    listTmp->getEle()->Yprime + SXL > listFinal->getEle()->Yprime
                                )
                                {
                                    listFinal->getEle()->color++;
                                }
                                listTmp->ptrSuiv();
                            }
                            listFinal->ptrSuiv();
                        }
                    }
                }

                sendData(listFinal);

            break;}

            case 63:{

                for(int tmp=0; tmp<5; tmp++)
                {
                    pthread_mutex_lock (& mu);
                    imgBas=cvQueryFrame(captureCameraB);
                    pthread_mutex_unlock (& mu);

                    binarisation();
                    regionGrowing();

                    if(tmp==0){
                        listFinal = analyseListeRegion(listBeforeTrait, IMG_WIDTH, IMG_HEIGHT);
                        listFinal->iniPtr();
                        while(listFinal->getEle()!=NULL){
                            listFinal->getEle()->color=0;
                            listFinal->ptrSuiv();
                        }
                    }else{
                        listTmp = analyseListeRegion(listBeforeTrait, IMG_WIDTH, IMG_HEIGHT);
                        listFinal->iniPtr();
                        while(listFinal->getEle()!=NULL){
                            listTmp->iniPtr();
                            while(listTmp->getEle()!=NULL){

                                if
                                (
                                    listTmp->getEle()->Xprime - SXL < listFinal->getEle()->Xprime &&
                                    listTmp->getEle()->Xprime + SXL > listFinal->getEle()->Xprime &&
                                    listTmp->getEle()->Yprime - SXL < listFinal->getEle()->Yprime &&
                                    listTmp->getEle()->Yprime + SXL > listFinal->getEle()->Yprime
                                )
                                {
                                    listFinal->getEle()->color++;
                                }
                                listTmp->ptrSuiv();
                            }
                            listFinal->ptrSuiv();
                        }
                    }
                }

                sendData(listFinal);

            break;}

            // --- Arrét du programme ---
            case -1:{
                on = 0;
            break;}
            case 69:{
                on = 0;
            break;}
        }

        // *****
        cout << endl;
        fflush(stdout);
    }
}