Exemple #1
0
void cameraTest(SmartCar * smartCar) {
	AIData data[2];
	int16_t pos[2]; 
	
	while (1) {
		AIData_init(&data[0], &smartCar->camera[0]);
		AIData_init(&data[1], &smartCar->camera[1]);

		binarization(&data[0]);
		binarization(&data[1]);
		
 		dumpData(data[0].arr, &smartCar->barLED[0]);
		dumpData(data[1].arr, &smartCar->barLED[1]);

		pos[0] = findIndexRL(&data[0]);
		pos[1] = findIndexLR(&data[1]);
		
		Segment_print(&smartCar->segment[0], (smartCar->camera[1].average + smartCar->camera[0].average)/2);
		Segment_print(&smartCar->segment[1], handling(pos[0], pos[1],smartCar->motor.targetSpeed));
		Segment_print(&smartCar->segment[2], Camera_getInterval() / 100);
		
		switch (board.button.check()) {
		case 4:
			Segment_print(&smartCar->segment[0], 0);
			Segment_print(&smartCar->segment[1], 0);
			Segment_print(&smartCar->segment[2], 0);
			return;
		}
	}
}
Exemple #2
0
void RecFile::SaveContent( )
{
	wxASSERT_MSG( m_imPagePtr, "ImPage should not be NULL" );
	wxASSERT_MSG( m_musDocPtr, "MusDoc should not be NULL" );
	wxASSERT( m_xml_root );
    
		
	if ( !m_isPreprocessed )
		return;
	else {
		m_imPagePtr->Save( m_xml_root ); // save in the RecFile directory		
		
		// binarization variables
		TiXmlElement binarization( "binarization" );
		binarization.SetAttribute( "pre_image_binarization_method", RecFile::m_pre_image_binarization_method );
		binarization.SetAttribute( "pre_page_binarization_method", RecFile::m_pre_page_binarization_method );
		binarization.SetAttribute( "pre_page_binarization_method_size", RecFile::m_pre_page_binarization_method_size );
		m_xml_root->InsertEndChild( binarization );
	}

	if ( !m_isRecognized )
		return;
	else
	{
		//possibility of MusDoc being a .mei not a .bin
		//MusMeiOutput *mei_output = new MusMeiOutput( m_musDocPtr, m_musDocPtr->m_fname );
		// save
		MusMeiOutput *mei_output = new MusMeiOutput( m_musDocPtr, m_musDocPtr->m_fname );
		mei_output->ExportFile();
		delete mei_output;
		
		MusMLFOutput *mlfoutput = new MusMLFOutput( m_musDocPtr, m_basename + "page.mlf", NULL );
		mlfoutput->m_pagePosition = true;
        // !!! No check if layout and page exist!
		mlfoutput->WritePage( (MusPage*)m_musDocPtr->m_children[0] , "staff", m_imPagePtr );
		delete mlfoutput;
		TiXmlElement root( "recpage" );
    
		// models
		TiXmlElement models( "models" );
		models.SetAttribute( "typographic_model",  m_rec_typ_model.c_str() );
		models.SetAttribute( "music_model",  m_rec_mus_model.c_str() );	
		root.InsertEndChild( models );
		
		// decoder
		TiXmlElement decoder( "decoder" );
		decoder.SetAttribute( "wrdtrns",  m_rec_wrdtrns.c_str() );
		decoder.SetAttribute( "lm_delayed",  m_rec_delayed );
		decoder.SetAttribute( "order",  m_rec_lm_order );
		decoder.SetDoubleAttribute( "scaling",  m_rec_lm_scaling );
		root.InsertEndChild( decoder );
			
		m_xml_root->InsertEndChild( root );
	}
}
void repixels(int dt_change, int do_change, int width, int height, long bmpSize, unsigned char* data)
{
	long i = 0;
	averagepixels(bmpSize, data);
	binarization(bmpSize, data);

	unsigned char* fake	   = (unsigned char*)malloc(sizeof(unsigned char) *  width * height);
	unsigned char* dt_data = (unsigned char*)malloc(sizeof(unsigned char) *  width * height);
	unsigned char* do_data = (unsigned char*)malloc(sizeof(unsigned char) *  width * height);

	singlizeimage(width, height, fake, data);
	filledges(width, height, fake);

	memcpy(dt_data, fake, sizeof(unsigned char) * width * height);
	memcpy(do_data, fake, sizeof(unsigned char) * width * height);

	for(i = 0; i <= dt_change; i++)
	{
		changepixels(DT_CHANGE_WHITE, width, height, bmpSize, dt_data);
	}
	changepixels(DO_CHANGE_WHITE, width, height, bmpSize, dt_data);

	for(i = 0; i <= do_change; i++)
	{
		changepixels(DO_CHANGE_WHITE, width, height, bmpSize, do_data);
	}

#ifdef DEBUG_OUTPUT
	writeToFile(2, width, height, dt_data, PROCESS_BOOL_SAVE_PATH1);
	writeToFile(2, width, height, do_data, PROCESS_BOOL_SAVE_PATH2);
#endif

	mergeimages(width, height, dt_data, do_data, fake);

	for(i = 0; i < REMOVE_LONELY_PIXEL; i++)
	{
		removelonelypixel(width, height, fake);
	}

	recoverimage(width, height, fake, data);	

	free(fake);
	free(dt_data);
	free(do_data);
}
Exemple #4
0
QImage Pdf::page(int i)
      {
      QImage image;
      // Paranoid safety check
      if (_document == 0) {
            return image;
            }
      
      Poppler::Page* pdfPage = _document->page(i);  // Document starts at page 0
      if (pdfPage == 0) {
            return image;
            }
            
      QSize size = pdfPage->pageSize();
      float scale = 2.0;
      // the size can be decided more intelligently
      image = pdfPage->renderToImage(scale*72.0, scale*72.0, 0, 0, scale*size.width(), scale*size.height());
      delete pdfPage;
      return binarization(image);
      }
int main(int argc, char** argv) {
   
    
    /**Abertura do arquivo da imagem*/
    printf("%s\n","Informe o nome do arquivo de imagem a ser aberto:");
    scanf("%s",Nome_arquivo);
    
    /**Função limpa tela*/
    reset();
    
    FILE *arquivo;
    
    /**Ler o arquivo*/
    arquivo = fopen(Nome_arquivo, "r");
    
    /**Faz o teste de erro na abertura do arquivo*/
    if(arquivo == NULL){
        printf("%s\n","Erro ao abrir o arquivo de imagem.");
    }else{
        printf("%s\n","Arquivo de imagem aberto com sucesso."); 
    }
    
        /**Ler os dados do cabeçalho*/
        fscanf(arquivo, "P3 %i %i 255",&largura, &altura);
    
    /**Comparação para ver o maior valor da matriz*/
    if (largura > altura) {
        
        max = largura;
    }else{
        max = altura;
    }
    
    /**Cria uma variável do tipo struct*/
    Pixel imagem[max][max];
    

    /**Ler cada Pixel alocando na variável referente ao struct*/
    for (i = 0; i < altura; i++){
        for(j = 0; j < largura; j++){
            fscanf(arquivo, "%i %i %i", &imagem[i][j].r, &imagem[i][j].g, &imagem[i][j].b);
        }
    }
    /**fecha o arquivo*/
    fclose(arquivo);
    




    do{
        
        /**Menu do programa sendo chamado*/
        menu();

        printf("\nDigite o comando:>");
        /**Comando para leitura do menu*/
        scanf("%s",comando);
        reset();
   
        /**converte as letras para minusculo afim de facilitar a comparação*/
        for(i=0;comando[i];i++)
            comando[i]=tolower(comando[i]);
   
        
       
        if(strcmp(comando,"lap")==0){
            printf("\nExecutando o comando: %s\n", comando);
            /**Chama o Filtro de laplace*/
            laplace(imagem);
            printf("%s\n", "Informe o nome desejado para saída:");
            /**Ler o novo nome para a imagem*/
            scanf("%s",arq);
            gerar_img(imagem, arq);
            printf("%s\n", "Imagem tratada com sucesso.");
            return (EXIT_SUCCESS);
            
        }else if(strcmp(comando,"gau")==0){
            printf("\nExecutando o comando: %s\n", comando);
            /**Chama o filtro de gaus*/
            gaussiano(imagem);
            printf("%s\n", "Informe o nome desejado para saída:");
            /**Ler o novo nome para a imagem*/
            scanf("%s",arq);
            gerar_img(imagem, arq);
            printf("%s\n", "Imagem tratada com sucesso.");
            return (EXIT_SUCCESS);
            
        }else if(strcmp(comando,"blu")==0){
            printf("\nExecutando o comando: %s\n", comando);
            /**Chama o filtro Blurring*/
            passa_baixa(imagem);
            printf("%s\n", "Informe o nome desejado para saída:");
            /**Ler o novo nome para a imagem*/
            scanf("%s",arq);
            gerar_img(imagem, arq);
            printf("%s\n", "Imagem tratada com sucesso.");
            return (EXIT_SUCCESS);
            
        }else if(strcmp(comando,"sha")==0){
            printf("\nExecutando o comando: %s\n", comando);
            /**Chama o filtro sharpening*/
            passa_alta(imagem);
            printf("%s\n", "Informe o nome desejado para saída:");
            /**Ler o novo nome para a imagem*/
            scanf("%s",arq);
            gerar_img(imagem, arq);
            printf("%s\n", "Imagem tratada com sucesso.");
            return (EXIT_SUCCESS);
            
        }else if(strcmp(comando,"amp")==0){
            printf("\nExecutando o comando: %s\n", comando);
           
            printf("\nInforme o zoom desejado:\n");
            /**Ler o zoom para ampliar a imagem*/
            scanf("%i",&zoom);
           
           
            printf("%s\n", "Informe o nome desejado para saída:");
            scanf("%s",arq);
            /**Chama a função para ampliar da imagem*/
            ampliar_img(strcat(arq,".ppm"),zoom,imagem);
            
            printf("%s\n", "Imagem ampliada com sucesso.");
            return (EXIT_SUCCESS);
            
        }else if(strcmp(comando,"red")==0){
            printf("\nExecutando o comando: %s\n", comando);
           
            printf("\nInforme o zoom desejado:\n");
            /**Ler o zoom para reduzir a imagem*/
            scanf("%i",&zoom);
           
           
            printf("%s\n", "Informe o nome desejado para saída:");
            scanf("%s",arq);
            /**Chama a função para redução da imagem*/
            reduzir_img(strcat(arq,".ppm"),zoom,imagem);
            
            printf("%s\n", "Imagem reduzida com sucesso.");
            return (EXIT_SUCCESS);
            
        }else if(strcmp(comando,"rel")==0){
            printf("\nExecutando o comando: %s\n", comando);
            /**Chama o filtro para aplicar o relevo na imagem*/
            relevo(imagem);
            printf("%s\n", "Informe o nome desejado para saída:");
            /**Ler o novo nome para a imagem*/
            scanf("%s",arq);
            gerar_img(imagem, arq);
            printf("%s\n", "Imagem tratada com sucesso.");
            return (EXIT_SUCCESS);
            
        }else if(strcmp(comando,"thr")==0){
            printf("\nExecutando o comando: %s\n", comando);
            printf("\nInforme o valor do thresholding:\n");
            scanf("%i",&thr);
            /**Chama o filtro da binarização*/
            binarization(imagem, thr);
            printf("%s\n", "Informe o nome desejado para saída:");
            /**Ler o novo nome para a imagem*/
            scanf("%s",arq);
            gerar_img(imagem, arq);
            printf("%s\n", "Imagem binarizada com sucesso.");
            return (EXIT_SUCCESS);

        }else if(strcmp(comando,"gra")==0){
            printf("\nExecutando o comando: %s\n", comando);
            /**Chama o filtro para grayscale*/
            grayscale(imagem);
            printf("%s\n", "Informe o nome desejado para saída:");
            /**Ler o novo nome para a imagem*/
            scanf("%s",arq);
            gerar_img(imagem, arq);
            printf("%s\n", "Imagem tratada com sucesso.");
            return (EXIT_SUCCESS);
            
        }else if(strcmp(comando,"inv")==0){
            printf("\nExecutando o comando: %s\n", comando);
            /**Chama o filtro para inverter as cores*/
            inverter(imagem);
            printf("%s\n", "Informe o nome desejado para saída:");
            /**Ler o novo nome para a imagem*/
            scanf("%s",arq);
            gerar_img(imagem, arq);
            printf("%s\n", "Imagem tratada com sucesso.");
            return (EXIT_SUCCESS);

        }else if(strcmp(comando,"esp")==0){
            printf("\nExecutando o comando: %s\n", comando);
            /**Chama a função para espelhar a imagem*/
            espelhar(imagem);
            printf("%s\n", "Informe o nome desejado para saída:");
            /**Ler o novo nome para a imagem*/
            scanf("%s",arq);
            gerar_img(imagem, arq);
            printf("%s\n", "Imagem espelhada com sucesso.");
            return (EXIT_SUCCESS);

        }else if(strcmp(comando,"rot")==0){
            printf("%s\n", "Informe o ângulo desejado desejado (90, 180, 270):");
            /**Detalha o ângulo de rotação*/
            scanf("%i",&angulo);
			
		if(angulo == 90){
			printf("\nExecutando o comando: %s\n", comando);
            /**Chama a função para rotacionar a imagem*/
            rotacionar_esq(imagem);
			printf("%s\n", "Informe o nome desejado para saída:");
            /**Ler o novo nome para a imagem*/
            scanf("%s",arq);
			gerar_img(imagem, arq);
            printf("%s\n", "Imagem rotacionada com sucesso.");
           	return (EXIT_SUCCESS);
            
		}else if(angulo == 180){
			printf("\nExecutando o comando: %s\n", comando);
            rotacionar_180(imagem);
			printf("%s\n", "Informe o nome desejado para saída:");
            /**Ler o novo nome para a imagem*/
            scanf("%s",arq);
			gerar_img(imagem, arq);
            printf("%s\n", "Imagem rotacionada com sucesso.");
           	return (EXIT_SUCCESS);
		
		}else if(angulo == 270){
			printf("\nExecutando o comando: %s\n", comando);
            rotacionar_270(imagem);
			printf("%s\n", "Informe o nome desejado para saída:");
            /**Ler o novo nome para a imagem*/
            scanf("%s",arq);
			gerar_img(imagem, arq);
            printf("%s\n", "Imagem rotacionada com sucesso.");
           	return (EXIT_SUCCESS);
		}
        }else{
            /** chama a funcao limpa tela*/
            reset();
            printf("\nComando desconhecido: %s\n",comando);
            
        }    

    }while(strcmp(comando,"exit")!=0);



        printf("%s\n", "Programa finalizado");
    
    /**Finaliza o programa*/
    return (EXIT_SUCCESS);
}
Exemple #6
0
void RecBookFile::SaveContent( )
{
    wxASSERT( m_xml_root );

    TiXmlElement book("book");
	int i;
    
    book.SetAttribute("RISM",  m_RISM.c_str() );
    book.SetAttribute("Composer", m_Composer.c_str() );    
    book.SetAttribute("Title", m_Title.c_str() );
    book.SetAttribute("Printer", m_Printer.c_str() );
    book.SetAttribute("Year", m_Year.c_str() );
    book.SetAttribute("Library", m_Library.c_str() );
    m_xml_root->InsertEndChild( book );
    
    TiXmlElement images("images");
    wxFileName dirname1 = wxFileName::DirName( m_imgFileDir );
    dirname1.MakeRelativeTo( wxFileName( m_filename ).GetFullPath() );
    //wxLogDebug( dirname1.GetPath() );
    images.SetAttribute("Path", dirname1.GetPath().c_str() );
    for ( i = 0; i < (int)m_imgFiles.GetCount(); i++)
    {
        TiXmlElement image("image");
        image.SetAttribute("filename", m_imgFiles[i].m_filename.c_str() );
        image.SetAttribute("flags", wxString::Format("%d", m_imgFiles[i].m_flags ).c_str() );
        images.InsertEndChild( image );
    }   
    m_xml_root->InsertEndChild( images );
    
    TiXmlElement axfiles("axfiles");
    wxFileName dirname2 = wxFileName::DirName( m_axFileDir );
    dirname2.MakeRelativeTo( wxFileName( m_filename ).GetFullPath() );
    //wxLogDebug( dirname2.GetPath() );
    axfiles.SetAttribute("Path", dirname2.GetPath().c_str() );
    for ( i = 0; i < (int)m_axFiles.GetCount(); i++)
    {
        TiXmlElement axfile("axfile");
        axfile.SetAttribute("filename", m_axFiles[i].m_filename.c_str() );
        axfile.SetAttribute("flags", wxString::Format("%d", m_axFiles[i].m_flags ).c_str() );
        axfiles.InsertEndChild( axfile );
    }   
    m_xml_root->InsertEndChild( axfiles );
	
    TiXmlElement adapt("adaptation");
    adapt.SetAttribute("full", wxString::Format("%d", m_fullOptimized ).c_str() );
	adapt.SetAttribute("nb_files_for_full", wxString::Format("%d", m_nbFilesOptimization ).c_str() );
    for ( i = 0; i < (int)m_optFiles.GetCount(); i++)
    {
        TiXmlElement adapt_file("file");
        adapt_file.SetAttribute("filename", m_optFiles[i].c_str() );
        adapt.InsertEndChild( adapt_file );
    }   
    m_xml_root->InsertEndChild( adapt );

	// binarization variables
	TiXmlElement binarization( "binarization" );
	binarization.SetAttribute( "pre_image_binarization_method", m_pre_image_binarization_method );
	binarization.SetAttribute( "pre_page_binarization_method", m_pre_page_binarization_method );
	binarization.SetAttribute( "pre_page_binarization_method_size", m_pre_page_binarization_method_size );
	binarization.SetAttribute( "pre_page_binarization_select", m_pre_page_binarization_select );
	m_xml_root->InsertEndChild( binarization );
}
int main(int argc, char** argv){
  setlocale( LC_CTYPE, "jpn");
  char* filename = argc >= 2 ? argv[1] : (char*)"card_ex2.JPG";
  //CvSeq* lines = 0;  
  char _filename[100];

  if((img0 = cvLoadImage(filename, -1)) == 0)
    return 0;
  
  //カード用変数宣言
  CvRect rect;
  double area;

  //パートごとのインスタンス宣言
  eachParts face;
  eachParts number;
  eachParts name;

  //操作説明
  printf("Hot Keys: \n""\tESC - プログラムを終了します.\n""\tr - 画像を初期化します.\n""\tf - 学生証を認識します.\n""\t1, 2, 3 - それぞれのキーで写真、番号、名前を個別に保存します(fを押した後のみ)\n""\tA - All param are saved and written(fを押したあとのみ)\n""\th - write to HTML file.\n");

  //ウィンドウ作成
  cvNamedWindow("binary1_frame", 1);
  cvNamedWindow("binary2_scan", 1);
  cvNamedWindow("学生証スキャナー", 1);
  cvMoveWindow("学生証スキャナー", 0, 0);
  cvMoveWindow("binary1_frame", 640, 0 );
  cvMoveWindow("binary2_scan", 0, 480);

  //コピー作成
  img = cvCloneImage(img0);
  tmp = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 3);
  
  //2値化
  gray = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 1);
  gray2 = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 1);

  //初期表示
  cvShowImage("学生証スキャナー", img);
  //cvShowImage("gray", gray);  
  //トラックバーの作成、スキャン用画像二値化
  cvCreateTrackbar( "Threshold", "binary2_scan", &level, 255, on_change);
  binarization(gray2, 1);
  
  //フレーム用画像二値化
  //cvCreateTrackbar( "Threshold", "binary1_frame", &level2, 255, on_change);
  cvCreateTrackbar( "Threshold1", "binary1_frame", &thr1, 255, on_change2);
  cvCreateTrackbar( "Threshold2", "binary1_frame", &thr2, 255, on_change2);
  binarization_canny(gray, thr1, thr2);

  cvShowImage("binary1_frame", gray);
  cvShowImage("binary2_scan", gray2);
  
  //set callback function for mouse operations
  cvSetMouseCallback("学生証スキャナー", on_mouse, 0);
  
  //キー操作
  for(;;){
    int c = cvWaitKey(0);
    
    if(c == 27)
      break;
    if(c == 'r'){
      cvZero(tmp);
      cvCopy(img0, img);
      binarization_canny(gray, thr1, thr2);
      cvShowImage("学生証スキャナー", img);
    }
    //枠検出
    if(c == 'f'){
      //ノイズ削減
      tmp2 = cvCreateImage (cvSize (img->width / 2, img->height / 2), img->depth, img->nChannels);
      cvPyrDown (img, tmp2, CV_GAUSSIAN_5x5);
      cvPyrUp(tmp2, img, CV_GAUSSIAN_5x5);
      
      
      CvMemStorage* storages = cvCreateMemStorage (0); //メモリストレージ
      CvSeq *contours = 0; //シーケンス
     
      //lines = cvHoughLines2(gray, storages, CV_HOUGH_PROBABILISTIC, 1, CV_PI/180, 80, 30, 10);
      int x = cvFindContours (gray, storages, &contours, sizeof (CvContour), CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);

      //cvErode(gray, gray);
      //cvDilate(gray, gray);

      /*for(int i = 0; i < lines->total; i++ ){
	CvPoint* line = (CvPoint*)cvGetSeqElem(lines,i);
	cvLine(img, line[0], line[1], CV_RGB(255,0,0), 3, 8 );
	}*/
      //cvDrawContours(img, contours, CV_RGB (255, 0, 0), CV_RGB (0, 255, 0), 1,1, CV_AA);
      rect = cvBoundingRect(contours, 0);
      area = cvContourArea (contours);
      std::cout << "矩形面積 = " << area << std::endl;
      if(area < 150000.0){
	std::cout << "読み取りエラー...パラメータを調整するか再起動してください" << std::endl;
      }
      
      cvRectangle (img, cvPoint (rect.x, rect.y), cvPoint (rect.x + rect.width, rect.y + rect.height), CV_RGB (255, 0, 0), 2);      
      cvShowImage("binary1_frame" ,gray);
      cvShowImage("学生証スキャナー", img);
      cvReleaseMemStorage(&storages);
      
      cvCopy(img0, img);
    }  
    
    /*
    //認識(仮)
    if(c == 'g'){
      cvSetImageROI(gray2, cvRect(min(pt.x, prev_pt.x), min(pt.y, prev_pt.y), abs(pt.x - prev_pt.x) ,abs(pt.y - prev_pt.y)));
      cvSaveImage("test.tiff", gray2);  
      
      // コマンド実行(結果はtmp.txtに保存)  
      system("tesseract test.tiff tmp -l jpn");   
      
      std::ifstream ifs("tmp.txt");  
      std::string str;
      std::getline(ifs, str);
      
      std::cout << "「" << str << "」…と、検出されました。" << std::endl;  
      cvResetImageROI(gray2);
    }
    */
    
    if(c == 'l'){
      count++;
      std::cout << "新たな画像ファイルの名前を入力してください。" << std::endl;
      scanf("%s", _filename);
      if((img0 = cvLoadImage(_filename, 1)) == 0)
	return 0;
      
      img = cvCloneImage(img0);
      binarization(gray2, 1);
      binarization_canny(gray, thr1, thr2);
      
      cvShowImage("学生証スキャナー", img);
      cvShowImage("binary1_frame", gray);
      cvShowImage("binary2_scan", gray2);
    }
    
    
    if(c == '1'){
      face.set(0.75, 0.21, 0.2, 0.5, rect, (char*)"face.jpg");
      if(face.makeRect() == 0){
	std::cout << "画像保存エラー!" << std::endl;
      }else{
	std::cout << "顔写真が保存されました。" << std::endl;      
      }
    }
    if(c == '2'){
      number.set(0.22, 0.4, 0.40, 0.1, rect, (char*)"number.tiff");
      if(number.makeRect_ocr() == 0){
	std::cout << "画像保存エラー!" << std::endl;
      }else{
	std::cout << "所属と学生証番号が保存されました。" << std::endl;      
      }
    }
    if(c == '3'){
      name.set(0.19, 0.58, 0.54, 0.13, rect, (char*)"name.tiff");
      if(name.makeRect_ocr() == 0){
	std::cout << "画像保存エラー!" << std::endl;
      }else{
	std::cout << "名前が保存されました。" << std::endl;      
      }
    }

    //ALL IN ONE
    if(c == 'a'){
      face.set(0.75, 0.21, 0.2, 0.5, rect, (char*)"face.jpg");
      if(face.makeRect() == 0){
	std::cout << "画像保存エラー!" << std::endl;
      }else{
	std::cout << "顔写真が保存されました。" << std::endl;      
      }
      
      number.set(0.22, 0.4, 0.40, 0.1, rect, (char*)"number.tiff");
      if(number.makeRect_ocr() == 0){
	std::cout << "画像保存エラー!" << std::endl;
      }else{
	std::cout << "所属と学生証番号が保存されました。" << std::endl;      
      }
      name.set(0.19, 0.58, 0.54, 0.13, rect, (char*)"name.tiff");
      if(name.makeRect_ocr() == 0){
	std::cout << "画像保存エラー!" << std::endl;
      }else{
	std::cout << "名前が保存されました。" << std::endl;      
      }
    }

    //HTML書き出し
    if(c == 'h'){
      std::ofstream ofs( "card.htm" );

      ofs << "<!DOCTYPE html><html><head><meta charset=\"utf-8\" /><title>学生証スキャナー</title></head><body><div style=\"margin:0px;padding:0px;\" align=\"center\"><table width=\"98%\" style=\"border-collapse: collapse;border:3px solid #FFFF66;background-color:#FFFFFF;color:#000000;text-align:left;\"><tbody><tr><th style=\"border:3px solid #FFFF66;background-color:#FFB533;color:#339900;text-align:center;\">番号</th><th style=\"border:3px solid #FFFF66;background-color:#FFB533;color:#339900;text-align:center;\">名前</th><th style=\"border:3px solid #FFFF66;background-color:#FFB533;color:#339900;text-align:center;\">顔写真</th></tr>";
      for(int j = 0; j < count; j++){
	char temp[50];
	sprintf(temp, "pic/00%dface.jpg", j+1);
	ofs << "<tr><td style=\"border:3px solid #FFFF66;text-align:center;\">" << save.str0[j] << "</td><td style=\"border:3px solid #FFFF66;text-align:center;\">" << save.str1[j] << "</td><td style=\"border:3px solid #FFFF66;text-align:center;\"><img src = \"" << temp << "\"></td></tr>";
      }
      
      ofs << "</tbody></table><div style=\"width:98%;\" align=\"right\"><a href=\"http://sunafukey.fc2web.com/htmltag/tablelist.html\" title=\"HTML表テンプレート\" style=\"color:#C0C0C0;font-size:50%;text-decoration:none;\">HTML表</a></div></div></body></html>" << std::endl;

      system("google-chrome file:///home/denjo/opencv/card.htm");
    }

   
  }
  //画像領域のリリース
  cvReleaseImage(&img);
  cvReleaseImage(&img0);
  cvReleaseImage(&tmp);
  cvReleaseImage(&tmp2);
  cvReleaseImage(&gray);
  cvReleaseImage(&gray2);
    
  return 0;
  
}
void on_change(int pos){

  binarization(gray2, 1);
  
}
Exemple #9
0
//==========================
//  Process Function
//==========================
void
ffos_process_image (unsigned char *data, int w, int h) {
  int threshold = otsu_i(data, w, h);
  global_cfg.otsu_threshold = threshold;
#ifndef __SOLVER__
  printf("otsu threshold: %d\n",threshold);
#endif
  // temporary data after image processing
  unsigned char * _temp = malloc(w * h * sizeof(unsigned char));
  unsigned char * pbuf  = malloc(w * h * sizeof(unsigned char));
  int erosion_count = global_cfg.erosion_count;
  memcpy(_temp, data, w * h * sizeof(unsigned char));
  binarization(pbuf, data, threshold, w, h);
  // erosion on the binary image
  for(int count = 1; count <= erosion_count; count++){
#ifndef __SOLVER__
    printf("erosion count = %d\n", count);
#endif
    erode(pbuf, w, h);
  }// end count
  // for temporary debug
#ifndef __SOLVER__
  write_pgm(pbuf, w, h, "erosion.pgm");
#endif

  int * x_point      = malloc(w*sizeof(int));
  int * y_point      = malloc(h*sizeof(int));
  int   num_center_x = calculate_x_position(pbuf, x_point, w, h);
  int   num_center_y = calculate_y_position(pbuf, y_point, w, h);
  global_cfg.num_x = num_center_x;
  global_cfg.num_y = num_center_y;
#ifndef __SOLVER__
  draw_bounding_box(_temp, w, h, x_point, y_point, num_center_x, num_center_y);
  // for temporary debug
  write_pgm((unsigned char *)_temp, w, h, "BondBox.pgm");
#endif
  //  localize the middle detected oled
  // firstly, locate the center oled (more complex methods can be used!)
    
  // coordinate of the middle led
  int index_center_x = num_center_x/2; 
  int index_center_y = num_center_y/2; 
  // approximate center of oled
  int   center_x = x_point[index_center_x];
  int   center_y = y_point[index_center_y];
  // decide the bonding box (consider the corner cases)
  rectangle box = get_bounding_box(center_x, center_y, w, h);

  int cog_x_i, cog_y_i;
  center_of_gravity_i(&cog_x_i, &cog_y_i, data, w, &box);
  global_cfg.cog_x_c = cog_x_i;
  global_cfg.cog_y_c = cog_y_i;

    
  free(x_point);
  free(y_point); 
  free(pbuf   );
  free(_temp  );
#ifndef __SOLVER__
  //Processing finished, print the results
  printf("==========================\n");
  printf("detected x positions = %d \n", num_center_x);
  printf("detected y positions = %d \n", num_center_y);
  printf("detected OLED = %d\n", num_center_x * num_center_y);
  if( (num_center_x == 0) || (num_center_y == 0) ){
    printf("WARNING: no OLED detected!!!\n");
  }
  printf("==========================\n");
    
  printf("index_center_x = %d\n", index_center_x);
  printf("index_center_y = %d\n", index_center_y);
  printf("num_center_x = %d\n", num_center_x);
  printf("num_center_y = %d\n", num_center_y);
  printf("==========================\n");
  printf("==========================\n");
  printf("Bonding Box of Center OLED\n");
  printf("(y_NW ,x_NW) = (%d, %d)\n", box.y_nw, box.x_nw);
  printf("(y_SE ,x_SE) = (%d, %d)\n", box.y_se, box.x_se);
  printf("==========================\n");
  printf("Calculated (moment) x, y position of the middle OLED\n");
  printf("x position of center OLED = %d (INT)\n", cog_x_i);
  printf("y position of center OLED = %d (INT)\n", cog_y_i);
  printf("==========================\n");
#endif
} // end process_image()