예제 #1
0
bool GMainEditor::forkProccesOCR_(pidID *pidIDArray,int ID, int maxFork){
    string str;
    pechaImg=LoadImageData(inputData.data["inputFile"],0);
    int pidID=fork();
    
	if (pidID < 0){
		error((char*)"ERROR on fork");
        return 0;
    }    
	if (pidID == 0)  {
		str=substr(0,str.rfind("."),str);
		str+=".html";   cout_<<str<<endl;
		inputData.data["inputFileName"]=inputData.data["siteName"];
		inputData.data["inputFileName"]+=substr(inputData.data["siteRoot"].size(),inputData.data["inputFile"]);
		//readPageHTML();
        cout<<"NEW START "<<inputData.data["inputFile"]<<endl;
		pechaDataLoaded=0;
		startOCR(pechaImg);
        pidIDArray[ID].status=0;
        cout<<"done "<<ID<<endl;
        remove(inputData.data["log"].c_str());
		exit(0);
	}
    pechaImg->destroy();
    return 1;
}
예제 #2
0
// Create a new STTexture using the pixel data from the given
// image (which will be copied in). Use the options to specify
// whether mip maps should be generated.
STTexture::STTexture(
    const STImage* image,
    ImageOptions options)
    : mWidth(-1)
    , mHeight(-1)
{
    Initialize();
    LoadImageData(image, options);
}
예제 #3
0
TiffIfd::TiffIfd(FILE *pFile, unsigned int ifdoffset,
		     bool loadall, unsigned int subfileoffset,
		     bool byte_swapping) :
  data_(NULL), subfileoffset_(subfileoffset), byte_swapping_(byte_swapping) {

  if (pFile == NULL)
    return;
  int iRV= fseek(pFile, ifdoffset, SEEK_SET);
  if (iRV != 0) {
    printf("Failed seek");
    fclose(pFile);
    return;
  }
  short nr;
  iRV = fread(&nr, sizeof(short), 1, pFile);
  if (iRV != 1) return;
  if (byte_swapping) ByteSwapInPlace(&nr, 1);
  printf("IFDSize: %d \n", nr);
  for(int tagindex=0 ; tagindex < nr; ++tagindex) {
    int pos = ftell(pFile);
    //    printf("File pointer %d\n", pos);
    TiffTag *tag = new TiffTag(pFile, byte_swapping_);
    tags_.push_back(tag);
  }
  printf("\n DIDIFD\n");
  iRV = fread(&nextifdoffset_, sizeof(unsigned int), 1, pFile);
  if (iRV != 1) {
    throw("Couldn't read nextifdoffset");
  }
  if (byte_swapping) ByteSwapInPlace(&nextifdoffset_, 1);

  // This disrupts the file pointer.
  LoadImageData(pFile, loadall);
  printf("Loaded Image data\n");
  if (loadall)
    LoadAll(pFile);
  printf("Listing tags\n");
  ListTags();
}
예제 #4
0
/*
int GImageEditor::forkImageProcess(pidID *pidIDArray,int maxFork,int ID){
    
    pechaImg=LoadImageData(inputData.data["inputFile"],0);
    if(pechaImg!=NULL){
        proccessImage(pechaImg);
        pechaImg->destroy();
    }else{
        cout<<"@@@!!!ERROR IN IMAGE!!!@@@"<<inputData.data["inputFile"]<<endl;
    }
   
     int pid = fork();
     if (pid < 0){
     cout<<"ERROR on fork ";
     pechaImg->destroy();
     return 0;
     }
     if (pid == 0)  {
     cout_<<"//___@inputID="<<ID<<endl;
     pechaImg=LoadImageData(inputData.data["inputFile"],0);
     if(pechaImg!=NULL){
     proccessImage(pechaImg);
     pechaImg->destroy();
     }else{
     cout<<"@@@!!!ERROR IN IMAGE!!!@@@"<<inputData.data["inputFile"]<<endl;
     }
     pidIDArray[ID].status=0;
     exit(0);
     }
     
    return 1;
    
}//______________________________________________
*/
int GImageEditor::forkImageProcess(pidID *pidIDArray,int maxFork,int ID){
    pechaImg=LoadImageData(inputData.data["inputFile"],0);
    int pid = fork();
    if (pid < 0){
        cout<<"ERROR on fork ";
        pechaImg->destroy();
        return 0;
    }    
    if (pid == 0)  {
        cout_<<"//___@inputID="<<ID<<endl;        
        if(pechaImg!=NULL){
            proccessImage(pechaImg);
        }else{
            cout<<"@@@!!!ERROR IN IMAGE!!!@@@"<<inputData.data["inputFile"]<<endl;
        }
        pidIDArray[ID].status=0;
        exit(0);
    }
    pechaImg->destroy();
    return 1;
    
}//______________________________________________
예제 #5
0
///диспетчер выполнения процесса создания  OCR  шрифта. Распознаем текст как контура, заносим в базу и распознаем.
void GMainEditor::buildOCRFont(){
    // Автоматическое масштабирование размеров картинки
    //ShowMessage("1start");
	cout_<<"Start#1 "<<inputData.data["inputFile"]<<endl;
	if(aliKali==NULL){aliKali=GFont::create();}
	int border;
	string str;
	int draw=1;
	int print=1;
	
	
	for(int index=0;index<inputData.fileList.size();index++){		
        
        inputData.data["inputFile"]=inputData.fileList[index];
        if(!is_file(inputData.data["inputFile"]))continue;
        pechaImg=LoadImageData(inputData.data["inputFile"],0); 
        if(!pechaImg){cout_<<"no open file"<<inputData.data["inputFile"]<<endl; return;}
        
        vector<stringOCR>strArray;  
        
        if(inputData.data["ocrData"]=="drawLetter"){
            draw=1;
            //inputData.c_out<<"<html><body><div style=\"position:absolute; left:0px; top:0px;\">";
            //inputData.c_out<<"<img src=\"__1draw.gif\"><br><div style=\"position:relative; left:20px;\">"<<endl;
        }
        DT("@4_1");
        //vectorBase[0].allVectorCount=0;
        border=0; //clock_t  tm_start1, tm_end1; double time1;  tm_start1=clock();
        setBit=GBitset::createResize(pechaImg,1,1,1);
        DT("@4_2");
        setBit->pageStringDetector(strArray,1); // Подпрограмма выделения строк и букв ПЕЧА ( РЕЛЬСЫ  )
        DT("@4_3");
        border=setBit->border_size();
        DT("@4_4");
        
        //cout_<<"strArray.size()="<<strArray.size()<<endl;
        //cout_<<"<div style=\"position:absolute; left:0px; top:0px;\">";
        //cout_<<"<img src=\"http://localhost/"<<inputData.inputFileName<<"\">\n";
        ///str=inputData.data["outFolder"]+"/1_out.jpg";
        //WriteImageData(pechaImg,"/2.jpg",1);    return;
        
        GFont* contourBase=GFont::create();
        //for(int a=0;a<2000;a++){
        //    GLetter *letter=GLetter::create();
        //    contourBase->letterSet[a]=letter;
        //    contourBase->letterSet[a]->recordStatus=0;
        // }
        
        GBitsetContour* setContour=GBitsetContour::createResize(pechaImg,1,1,0);
        //setContour->drawContour();
        //WriteImageData(setContour->drawData,"/1.jpg",1);    return;
        
        setContour->buildGFont(contourBase,strArray);
        
        //int index=0;
        // while(1){
        
        //if(contourBase->letterSet[index]->recordStatus)contourBase->letterSet[index]->drawContour();
        //break;   
        
        //}
        int maxID=0;
        //for(int a=0;a<aliKali->letterCount();a++){
        //    if(aliKali->letterSet[a]->idNumber>maxID)maxID=aliKali->letterSet[a]->idNumber;
       // }
        contourBase->setLineFromArray(strArray);
        /*for(int a=0;a<contourBase->letterCount();a++){
         aliKali->letterSet[aliKali->letterCount()]=contourBase->letterSet[a];
         maxID++;
         aliKali->letterSet[aliKali->letterCount()]->idNumber=maxID;
         
         }
         */  
	    pechaImg->destroy();
		setContour->destroy();
		
    }
    fontEditor->aliKali=aliKali;  
    
    //WriteImageData(setContour->drawData,"/1.jpg",1);   
    
    
    
}
예제 #6
0
void GMainEditor::startOCRBatch(){
    
    imageEditor=(GImageEditor*)inputData.imageEditor;
    fontEditor=(GFontEditor*)inputData.fontEditor;
    logicProcessor=(GLogicProcessor*)inputData.logicProcessor;
    if(!logicProcessor->dictionaryReady)logicProcessor->readDictionary();
    aliKali=fontEditor->aliKali;

    
	string strHeaderHTML,srcLine,str;
	string  path=inputData.data["tablePath"]+"/header.xml";
	DIR *dir;
	//int mode;	
	int i=0;
    //читаем статистику использования букв книги
    //readLetterStat();
    //загружаем базу данных букв
    
#ifdef FORK
     int maxFork=inputData.num_cores*0.75;
     int pid;
     pidID *pidIDArray;
     
    
    if(inputData.fileList.size()>1){
        int countFork=0; 
        MemoryFile *pidData_mf;  //main file for conection with child process
        //inputData.data["statPath"].c_str()
        time_t seconds;    seconds = time (NULL);
        ostringstream out;  out<<"/tmp/"<<seconds;
        string path=out.str();
        pidData_mf=MemoryFile::create(path.c_str(), MemoryFile::if_exists_keep_if_dont_exists_create);
        pidData_mf->resize(sizeof(pidID)*maxFork);
        pidIDArray=(pidID*)pidData_mf->data(); //array which can be share between processes.
        
        
        for(int index=0;index<maxFork;index++){
            //cout_<<"pidIDArray["<<index<<"].status="<<pidIDArray[index].status<<endl;
            pidIDArray[index].status=0;
        }

        int ID=0;
        
        while(i<inputData.fileList.size()){
            cout<<"NEW file#1 "<<inputData.fileList[i]<<endl;
            if( ( dir=opendir(inputData.fileList[i].c_str()))!=NULL){
                i++; continue;
            }	
            
            inputData.data["inputFile"]=inputData.fileList[i];
            
            string  path=inputData.data["inputFile"];    //проверяем есть ли такой распознаный файл
            path=substr(0,(int)path.rfind("."),path);
            string volume=path;
            string fileIndex=fileName(path);
            path+=".xml";
            if(is_file(path)){i++; continue;}
            
            
            if(!forkProccesOCR_(pidIDArray,ID,maxFork)){
                cout<<"ERROR on fork return";
                sleep(1); continue; 
            };
            i++;if(i==inputData.fileList.size())break;
            countFork++;

            for(int index=0;index<maxFork;index++)cout<<pidIDArray[index].status<<" ";
            cout<<endl;
            
            ID=100; int status;
            while(ID==100){
                if(countFork<=maxFork){     //есть свободные слоты для новых процессов
                    for(int index=0;index<maxFork;index++){  //маркируем слот как занятый
                        //cout_<<"pidIDArray["<<index<<"].status="<<pidIDArray[index].status<<endl;
                        if(pidIDArray[index].status==0){
                          ID=index;
                          pidIDArray[index].status=1;
                          break;
                        }    
                    }
                }else{
                    int forkStatusCount=0;
                    for(int index=0;index<maxFork;index++){   //подсчитываем количество активных процессов
                        if(pidIDArray[index].status==1)forkStatusCount++;
                    }
                    if(forkStatusCount==countFork){sleep(1); continue;};     //ждем завершения процесса
                    wait(&status);                           //регистрируем с системе завершенный процесс
                    countFork--;
                }   
            }	
        }
            
    }else{
        inputData.data["inputFile"]=inputData.fileList[0];
        pechaImg=LoadImageData(inputData.data["inputFile"],0); 
        startOCR(pechaImg);
    }
    
    
#else
    cout<<"NO FORK";
	while(i<inputData.fileList.size()){
		if( ( dir=opendir(inputData.fileList[i].c_str()))!=NULL){
			readDirectoryToArray(inputData.fileList, inputData.fileList[i],"img");
			i++; continue;
		}	
		GBitmap* pechaImg;
		inputData.data["inputFile"]=inputData.fileList[i];

        if(!is_file(inputData.data["inputFile"]))continue;
        pechaImg=LoadImageData(inputData.data["inputFile"],0); 
        if(!pechaImg){cout_<<"no open file"<<inputData.data["inputFile"]<<endl; return;}
        
        str=inputData.data["inputFile"];
		str=substr(0,str.rfind("."),str);
		str+=".html";   //cout_<<str<<endl;
		inputData.data["inputFileName"]=inputData.data["siteName"];
		inputData.data["inputFileName"]+=substr(inputData.data["siteRoot"].size(),inputData.data["inputFile"]);

		//readPageHTML();
		inputData.c_out.open(str.c_str());
		pechaDataLoaded=0;
		startOCR(pechaImg);
        pechaImg->destroy();
		inputData.c_out.close();
		i++;
	}
	
#endif		
	//drawLettersInCorrectionTable(DRAW_BASE);
	
	cout_<<"COMPLETE"<<endl;
	
}//____________________________________________________________________________
예제 #7
0
void GMainEditor::startOCRSystem(){
    
	string strHeaderHTML,srcLine,str;
	string  path=inputData.data["tablePath"]+"/header.xml";
	DIR *dir;
	//int mode;
	int i=0;
    uint freeMemory;
    //читаем статистику использования букв книги
    //readLetterStat();

    int maxProcess=inputData.num_cores*0.85;
    pidID *pidIDArray;
    
    if(inputData.data["pathDB"]!=""){
        inputData.data["inputFile"]=inputData.fileList[0];
        pechaImg=LoadImageData(inputData.data["inputFile"],0);
        startOCR(pechaImg);

        MemoryFile *pidData_mf=MemoryFile::create(inputData.data["pathDB"].c_str(),
                                                  MemoryFile::if_exists_keep_if_dont_exists_create);
        int ID=atoi(inputData.data["ID"].c_str());
        pidIDArray=(pidID*)pidData_mf->data(); //array which can be share between processes.
        pidIDArray[ID].status=0;
        cout<<"done OCR";
        inputData.log<<" done OCR"<<endl;
        inputData.log.close();
        remove(inputData.data["log"].c_str());
        exit(0);
    }
    
    if(inputData.fileList.size()>1){
        int countProcess=0;
        MemoryFile *pidData_mf;  //main file for inter proccess communications
        //inputData.data["statPath"].c_str()
        time_t seconds;    seconds = time (NULL);
        ostringstream out;  out<<"/tmp/"<<seconds;
        string pathDB=out.str();
        pidData_mf=MemoryFile::create(pathDB.c_str(), MemoryFile::if_exists_keep_if_dont_exists_create);
        pidData_mf->resize(sizeof(pidID)*maxProcess);
        pidIDArray=(pidID*)pidData_mf->data(); //array which can be share between processes.
        
        
        for(int index=0;index<maxProcess;index++){
            //cout_<<"pidIDArray["<<index<<"].status="<<pidIDArray[index].status<<endl;
            pidIDArray[index].status=0;
        }
        
        int ID=0;
        
        while(i<inputData.fileList.size()){

            if( ( dir=opendir(inputData.fileList[i].c_str()))!=NULL){
                i++; continue;
            }
            
            inputData.data["inputFile"]=inputData.fileList[i];
            string next="";
            if(i<inputData.fileList.size()-2){
                next=inputData.fileList[i+1];
                next=str_replace(".tif",".html",next);
                next=str_replace(".jpg",".html",next);
            }
            
            string  path=inputData.data["inputFile"];    //проверяем есть ли такой распознаный файл
            path=substr(0,(int)path.rfind("."),path);
            string volume=path;
            string fileIndex=fileName(path);
            path+=".html";
            if(is_file(path)){i++; continue;}
            
            
            while(1){
                //проверяем загрузку системы
                str=run("vm_stat");
                vector<string>vm=explode("\n", str);
                str=str_replace("Pages free:", "", vm[1]);
                str=str_replace(" ", "", str);
                str=str_replace(".", "", str);
                freeMemory=atoi(str.c_str());
                freeMemory=(freeMemory*4.096)/1000;
                //cout<<"@freeMemory:"<<freeMemory<<endl;
                
                if(freeMemory<10){
                    cout<<"critical memory loading error";
                    run("killall OCRLib");
                    exit(0);
                }
                if(freeMemory>500)break;
                cout<<"@ no free memory for process. freeMemory:"<<freeMemory<<endl;
                sleep(10);
            }

            cout<<"NEW file#1 "<<inputData.fileList[i]<<endl;
            ostringstream out;
            out<<inputData.data["rootApp"]<<" \"xml=<fileList>"<<inputData.data["inputFile"]<<
            "</fileList><ocrData>"<<inputData.data["ocrData"]<<"</ocrData>"<<
            "<ocrLn>"<<inputData.data["ocrLn"]<<"</ocrLn>"<<"<pathDB>"<<pathDB<<"</pathDB>"<<
            "<ID>"<<ID<<"</ID><nextPage>"<<next<<"</nextPage><scale>"<<inputData.data["scale"]<<"</scale>\" &";
            string cmd=out.str();
            //cout<<cmd; exit(0);
            system(cmd.c_str());
            //sleep(1); //continue;
            
            
            i++;if(i==inputData.fileList.size())break;
            countProcess++;
            
            for(int index=0;index<maxProcess;index++)cout<<pidIDArray[index].status<<" ";
            cout<<endl;
            
            ID=100; int status;
            while(ID==100){
                if(countProcess<=maxProcess){     //есть свободные слоты для новых процессов
                    for(int index=0;index<maxProcess;index++){  //маркируем слот как занятый
                        //cout_<<"pidIDArray["<<index<<"].status="<<pidIDArray[index].status<<endl;
                        if(pidIDArray[index].status==0){
                            ID=index;
                            pidIDArray[index].status=1;
                            break;
                        }
                    }
                }else{
                    int processStatusCount=0;
                    for(int index=0;index<maxProcess;index++){   //подсчитываем количество активных процессов
                        if(pidIDArray[index].status==1)processStatusCount++;
                    }
                    if(processStatusCount==countProcess){sleep(1); continue;};     //ждем завершения процесса
                    countProcess--;
                }
            }
        }
        
    }else{
        i=0;
        //while(i<inputData.fileList.size()){
        //        if( ( dir=opendir(inputData.fileList[i].c_str()))!=NULL){
        //            i++; continue;
        //        }
            inputData.data["inputFile"]=inputData.fileList[0];
            pechaImg=LoadImageData(inputData.data["inputFile"],0);
            startOCR(pechaImg);
        //    i++;
        //}
    }
}
예제 #8
0
ImageView::ImageView(util::MrcStack* vi, QWidget* parent, Qt::WindowFlags flags): QMainWindow(parent, flags)
{
setAttribute(Qt::WA_DeleteOnClose);
  setAttribute(Qt::WA_AlwaysShowToolTips);
  setAnimated(false);
  mVi   = vi;
  nx = mVi->Width();
  ny = mVi->Height();
  nz = mVi->Size();
//   qDebug()<<"here";
  cx = 0;
  cy = 0;
  cz = nz/2;
  mZoom = 1;
  mx = nx*mZoom;
  my = ny*mZoom;
  mz = nz*mZoom;
  mXorigin1 = mz + XYZ_BSIZE + XYZ_GSIZE + 2*FRAM_BORDER;
  mYorigin1 = XYZ_BSIZE;
  mXorigin2 = XYZ_BSIZE;
  mYorigin2 = mz + XYZ_BSIZE + XYZ_GSIZE + 2*FRAM_BORDER;
  mWidth = mz+mx+ALL_BORDER+4*FRAM_BORDER;
  mHeight = mz + my + ALL_BORDER +40+4*FRAM_BORDER+20;
  
  //对于过大图像,要定义一个新mzoom值
  if(mHeight > 700 || mWidth > 900){
    int w = mWidth;
    int h = mHeight;
    float d = 0.25;
    while(1){
      if(mZoom>d)
      mZoom -= d;
      else{
	d/=5;
	mZoom-=d;
      }
      mHeight = h*mZoom;
      mWidth = w*mZoom;
      qDebug()<<"window size : "<<mWidth<<"*"<<mHeight;
      if(mHeight <= 900 && mWidth <=1100)
	break;
    }
  mx = nx*mZoom;
  my = ny*mZoom;
  mz = nz*mZoom;
  mXorigin1 = mz + XYZ_BSIZE + XYZ_GSIZE + 2*FRAM_BORDER;
  mYorigin1 = XYZ_BSIZE;
  mXorigin2 = XYZ_BSIZE;
  mYorigin2 = mz + XYZ_BSIZE + XYZ_GSIZE + 2*FRAM_BORDER;
  mWidth = mz+mx+ALL_BORDER+4*FRAM_BORDER;
  mHeight = mz + my + ALL_BORDER +40+4*FRAM_BORDER+20;
  }
  
  m_OpenZoom = mZoom;
  m_RelativeZoom = mZoom/m_OpenZoom;
  wx = mx;
  wy = my;
  wz = mz;
  
  qDebug()<<"mzoom : "<<mZoom;
  resize(mWidth , mHeight);
   mFdatayz = new unsigned char[nz*ny];
  mFdataxz = new unsigned char[nx*nz];
  mFdataxy = new unsigned char[nx*ny];
//   mCurView = -1;
  m_imginfo = new ImgInfo(this);
  m_imginfo->setAttribute(Qt::WA_DeleteOnClose);
  
   LoadImageData();
  CreateActions();
  CreateToolBars();  
  CreateStatusBar();
  CreateXYZView();
  
  m_XSlider->setRange(0 , nx-1);
  m_XSlider->setValue(cx);
  m_YSlider->setRange(0,ny-1);
  m_YSlider->setValue(cy);
  m_ZSlider->setRange(0,nz-1);
  m_ZSlider->setValue(cz);
  qDebug()<<"here";
  connect(m_imginfo , SIGNAL(destroyed(QObject*)) , this , SLOT(close()));
    connect(m_imginfo , SIGNAL(Adjust()) , this , SLOT(On_Adjust()));
    
    QRect rect = QApplication::desktop()->availableGeometry();
  move((rect.width()-mWidth)/2 , (rect.height()-mHeight)/2);
  show();
}
예제 #9
0
void GImageEditor::imageProcess(){
    
    cout<<"START image";
    
	string strHeaderHTML,srcLine,str;
	string  path=inputData.data["tablePath"]+"/header.xml";
	replace(path.begin(),path.end(),'\\','/');
    
	if(!inputData.fileList.size()){
		readDirectoryToArray(inputData.fileList,inputData.data["inputFolder"],"img");
	}
    
    //cout<<"inputData.fileList.size()="<<inputData.fileList.size();
    
#ifdef FORK11
    int maxFork=inputData.num_cores*2;  //обработка изображений легче чем OCR
    pidID *pidIDArray;
    
    
    MemoryFile *pidData_mf;  //main file for conection with child process
    pidData_mf=MemoryFile::create(inputData.data["statPath"].c_str(), MemoryFile::if_exists_keep_if_dont_exists_create);
    pidData_mf->resize(sizeof(pidID)*maxFork);
    pidIDArray=(pidID*)pidData_mf->data(); //array which can be share between processes.
    
    for(int index=0;index<maxFork;index++)pidIDArray[index].status=0;
    //for(int index=0;index<maxFork;index++)cout_<<pidIDArray[index].status;
    
    
    int ID=0;
    unsigned int i=0;
    DIR *dir;
    int countFork=0;
    int status;
    while(i<inputData.fileList.size()){
        
        if( ( dir=opendir(inputData.fileList[i].c_str()))!=NULL){
            cout_<<"NEW DIR#1 "<<inputData.fileList[i]<<endl;
            readDirectoryToArray(inputData.fileList, inputData.fileList[i],"img");
            i++; continue;
        }
        //cout_<<"NEW START"<<endl;
        
        inputData.data["inputFile"]=inputData.fileList[i];
        int statusFork=forkImageProcess(pidIDArray,maxFork,ID);
        if(statusFork==0){
            wait(&status);sleep(1);  //пробуем подождать
            cout<<"fork error. Try to continue;"<<endl;
            continue;
        }
        if(statusFork==3)i++;  //пропускаем битую картинку
        countFork++;
        i++;
        if(i==inputData.fileList.size())break;
        
        cout_<<" pidIDArray[0].status= "<<pidIDArray[0].status<<" >> ";
        for(int index=0;index<maxFork;index++)cout_<<pidIDArray[index].status<<" ";
        cout_<<endl;
        
        ID=100;
        while(ID==100){
            if(countFork<maxFork-1)break;             //есть свободные слоты для новых процессов
            int forkStatusCount=0;
            for(int index=0;index<maxFork;index++){   //подсчитываем количество активных процессов
                if(pidIDArray[index].status==1)forkStatusCount++;
            }
            if(forkStatusCount==countFork){sleep(1);continue;}     //нет завершенных процессов
            wait(&status);                           //регистрируем с системе завершенный процесс
            countFork--;
            for(int index=0;index<maxFork;index++){  //маркируем слот как свободный
                //cout_<<"pidIDArray["<<index<<"].status="<<pidIDArray[index].status<<endl;
                if(pidIDArray[index].status==0){
                    
                    ID=index;
                    pidIDArray[index].status=1;
                    break;
                }
            }
            
        }
    }
    
	
#else
    DIR *dir;
    int printIndex=0;
    string path0="";
    string path1="";

    string mode="tif";
    GBitmap *printPage0;
    GBitmap *printPage1;

	for(int i=0;i<inputData.fileList.size();i++){
        cout<<"inputData.fileList["<<i<<"]="<<inputData.fileList[i]<<END;
        if( ( dir=opendir(inputData.fileList[i].c_str()))!=NULL){
            cout_<<"NEW DIR#1 "<<inputData.fileList[i]<<endl;
            readDirectoryToArray(inputData.fileList, inputData.fileList[i],"img");
            continue;
        }
        cout<<"NEW START"<<endl;
        inputData.data["inputFile"]=inputData.fileList[i];
        pechaImg=LoadImageData(inputData.data["inputFile"],0);
        proccessImage(pechaImg);
        if(inputData.data["fileSave"]=="print3_Pages"){
            //if(pechaImg->rows()<1200||pechaImg->rows()>1300)pechaImg->scaleFast((float)1216/pechaImg->rows());
            cout<<"printIndex="<<printIndex<<" pechaImg->rows()="<<pechaImg->rows()<<endl;

            
            if(printIndex==0){
                path=str_replace(".jpg", ".tif", inputData.data["inputFile"]);
                path=str_replace(".JPG", ".tif", path);
                path=str_replace(".jpg", ".tif", path);
                if(path.find(".tif")==-1)path=path+".tif";
                path0=str_replace(".tif", "_print0.tif", path);
                path1=str_replace(".tif", "_print1.tif", path);
                printPage0=GBitmap::create(pechaImg->columns(),pechaImg->rows()*3);
                printPage1=GBitmap::create(pechaImg->columns(),pechaImg->rows()*3);

                printPage0->drawImg(pechaImg,0, 0);
            }
            if(printIndex==1){
                cout<<" pechaImg->rows()*2="<<pechaImg->rows()*2<<endl;
                printPage1->drawImg(pechaImg,0, pechaImg->rows()*2);
            }
            
            if(printIndex==2){
                printPage0->drawImg(pechaImg,0, pechaImg->rows());
            }
            if(printIndex==3){
                printPage1->drawImg(pechaImg,0, pechaImg->rows());
            }
            if(printIndex==4){
                printPage0->drawImg(pechaImg,0, pechaImg->rows()*2);
            }
            if(printIndex==5){
                printPage1->drawImg(pechaImg,0, 0);
            }
            if(printIndex==5||i==inputData.fileList.size()-1){            //cout_<<" path="<<path<<endl;
                WriteImageData(printPage0,path0,0,mode);
                WriteImageData(printPage1,path1,0,mode);
                printPage0->destroy();
                printPage1->destroy();
                printIndex=-1;
            }
            printIndex++;
        }
        if(inputData.data["fileSave"]=="print3Pages"){
            //if(pechaImg->rows()<1200||pechaImg->rows()>1300)pechaImg->scaleFast((float)1216/pechaImg->rows());
            cout<<"printIndex="<<printIndex<<" pechaImg->rows()="<<pechaImg->rows()<<endl;
            int dY=21;
            int dX=21;
            
            if(printIndex==0){
                path=str_replace(".jpg", ".tif", inputData.data["inputFile"]);
                path=str_replace(".JPG", ".tif", path);
                path=str_replace(".jpg", ".tif", path);
                if(path.find(".tif")==-1)path=path+".tif";
                path0=str_replace(".tif", "_print0.tif", path);
                path1=str_replace(".tif", "_print1.tif", path);
                printPage0=GBitmap::create(pechaImg->columns(),pechaImg->rows()*2);
                printPage1=GBitmap::create(pechaImg->columns(),pechaImg->rows()*2);
                
                printPage0->drawImg(pechaImg,-dX, -dY);
            }
            if(printIndex==1){
                cout<<" pechaImg->rows()="<<pechaImg->rows()<<endl;
                printPage1->drawImg(pechaImg,-dX, pechaImg->rows()+dY);
            }
            
            if(printIndex==2){
                printPage0->drawImg(pechaImg,-dX, pechaImg->rows()+dY);
            }
            if(printIndex==3){
                printPage1->drawImg(pechaImg,-dX, -dY);
            }
           
            if(printIndex==3||i==inputData.fileList.size()-1){            //cout_<<" path="<<path<<endl;
                WriteImageData(printPage0,path0,0,mode);
                WriteImageData(printPage1,path1,0,mode);
                printPage0->destroy();
                printPage1->destroy();
                printIndex=-1;
            }
            printIndex++;
        }
        pechaImg->destroy();
    }
	
#endif
    //inputData.c_out.close();
    
    
	
}//______________________________________________
예제 #10
0
//-----------------------------------------------------------------------------
// Unserialization
//-----------------------------------------------------------------------------
bool CVTFTexture::Unserialize( CUtlBuffer &buf, bool bBufferHeaderOnly, int nSkipMipLevels )
{
	// When unserializing, we can skip a certain number of mip levels,
	// and we also can just load everything but the image data

	VTFFileHeader_t header;
	memset( &header, 0, sizeof(VTFFileHeader_t) );

	buf.Get( &header, sizeof(VTFFileHeader_t) );
	if (!buf.IsValid())
	{
		Warning("*** Error unserializing VTF file... is the file empty?\n");
		return false;
	}

	// Validity check
	if ( Q_strncmp( header.fileTypeString, "VTF", 4 ) )
	{
		Warning("*** Tried to load a non-VTF file as a VTF file!\n");
		return false;
	}

	if( header.version[0] != VTF_MAJOR_VERSION )
	{
		Warning("*** Encountered VTF file with an invalid version!\n");
		return false;
	}
	if( (header.flags & TEXTUREFLAGS_ENVMAP) && (header.width != header.height) )
	{
		Warning("*** Encountered VTF non-square cubemap!\n");
		return false;
	}
	if( header.width <= 0 || header.height <= 0 )
	{
		Warning( "*** Encountered VTF invalid texture size!\n" );
		return false;
	}

	m_nWidth = header.width;
	m_nHeight = header.height;
	m_Format = header.imageFormat;

	m_nFlags = header.flags;

	m_nFrameCount = header.numFrames;

	// NOTE: We're going to store space for all mip levels, even if we don't 
	// have data on disk for them. This is for backward compatibility
	m_nMipCount = ComputeMipCount();
	m_nFaceCount = (m_nFlags & TEXTUREFLAGS_ENVMAP) ? CUBEMAP_FACE_COUNT : 1;

	m_vecReflectivity = header.reflectivity;
	m_flBumpScale = header.bumpScale;

	// FIXME: Why is this needed?
	m_iStartFrame = header.startFrame;

	// FIXME: Remove
	// This is to make sure old-format .vtf files are read properly
	m_pVersion[0] = header.version[0];
	m_pVersion[1] = header.version[1];

	if( header.lowResImageWidth == 0 || header.lowResImageHeight == 0 )
	{
		m_nLowResImageWidth = 0;
		m_nLowResImageHeight = 0;
	}
	else
	{
		m_nLowResImageWidth = header.lowResImageWidth;
		m_nLowResImageHeight = header.lowResImageHeight;
	}
	m_LowResImageFormat = header.lowResImageFormat;
	
	// Helpful for us to be able to get VTF info without reading in a ton
	if (bBufferHeaderOnly)
		return true;

	if (!LoadLowResData( buf ))
		return false;

	if (!LoadImageData( buf, header, nSkipMipLevels ))
		return false;

	return true;
}
예제 #11
0
void GMainEditor::startOneFileOCR(){

    pechaImg=LoadImageData(inputData.data["inputFile"],0); 
    cout<<"Start#1 "<<inputData.data["inputFile"]<<END; 
    if(!pechaImg){cout<<"no open file"<<inputData.data["inputFile"]<<endl; return;}
	
    inputData.data["ocrData"]="oneStringOCR";
    mainString="";
    
    vector<stringOCR>strArray;  
    int border;
    string str;
    string xmlString;
    int print=1;
    
	DT("@4_1");
    //vectorBase[0].allVectorCount=0;
	border=0; 
    setBit=GBitset::createResize(pechaImg,1,1,1);
    DT("@4_2");
    setBit->pageStringDetector(strArray,1); // Подпрограмма выделения строк и букв ПЕЧА ( РЕЛЬСЫ  )
    DT("@4_3");
    border=setBit->border_size();
    DT("@4_4");
    setBit->destroy();
    
    //получили координаты строк. Создаем новый процесс для каждой строки
    vector<int> pidID(inputData.num_cores);
    int status,pid;
    
    for(int index=0;index<pidID.size();index++){
        pidID[index]=0;
    }
    for(int a=0;a<strArray.size();a++)strArray[a].selectFlag=0;
    
    int i=strArray.size()-1;
    int processCount=0;
    while(i>=0){
        cout<<"NEW string# "<<i<<endl;
        for(int index=0;index<pidID.size();index++){
            if(pidID[index]==0){
                strArray[i].selectFlag=1;
                processCount++;
                pidID[index] = fork();
                if (pidID[index] < 0)
                    error((char*)"ERROR on fork");
                if (pidID[index] == 0)  {
                    
                    GBitsetOCR *setOCR=GBitsetOCR::createResize(pechaImg,1,1);
                    //if(NewLetterOnlyBtn->Checked==true) {mode=NEWLETTERINBOOK;}else{mode=ALL_LETTER;}
                    
                    setOCR->setData(
                                    aliKali,
                                    strArray,
                                    correctionTable,
                                    logicProcessor,
                                    iLeft,
                                    iTop,
                                    border,
                                    ALL_LETTER);
                    mainString=setOCR->mainString;
                    xmlString=setOCR->xmlString;
                    //cout<<"mainString="<<mainString<<endl;
                    ostringstream out;
                    out<<inputData.data["root"]<<"edit/OCR/_DATA/";
                    out.width(4);
                    out.fill('0');
                    out<<strArray.size()-i-1<<".html";
                    string path=out.str();
                    writeText(mainString,path);
                    out.str("");
                    out<<inputData.data["root"]<<"edit/OCR/_DATA/";
                    out.width(4);
                    out.fill('0');
                    out<<strArray.size()-i-1<<".xml";
                    path=out.str();
                    writeText(xmlString,path);
                    setOCR->destroy();
                    exit(0);
                }
                strArray[i].selectFlag=0;
                i--;if(i==-1)break;
            } 	
        }	
        
        pid=wait(&status); cout<<"new pecha";
        for(int index=0;index<pidID.size();index++){
            if(pid==pidID[index]){pidID[index]=0;processCount--;}
        }	
    }
    cout<<"start processCount="<<processCount<<endl;
    while(processCount){pid=wait(&status);
        if(pid>0){
         processCount--;
         cout<<"pid="<<pid<<" processCount="<<processCount<<endl;
        }
    }
    
    cout<<"collect all fork result in one file";
    
    vector<string>fileList;
    string path=inputData.data["root"]+"edit/OCR/_DATA/";
    int count=0;
    while(1){
       readDirectoryToArray(fileList, path,"html");
        if(fileList.size()!=strArray.size()){         
            cout<<"data not ready. has"<<fileList.size()<<" files. must be "<<strArray.size()<<" wait 2 sec."<<endl;
            count++; if(count==11)break;
             fileList.resize(0);
            sleep(2); 
        }else break;
    }
    
    for(int a=0;a<fileList.size();a++){
        string str; readText(str,fileList[a]);
        mainString+=str;
    }
    //cout<<"mainString="<<mainString<<endl;
    drawStrArray(strArray,border);
    xmlString="";  fileList.resize(0);
    readDirectoryToArray(fileList, path,"xml");
    for(int a=0;a<fileList.size();a++){
        string str; readText(str,fileList[a]);
        xmlString+=str;
    }
    //cout<<"xmlString="<<xmlString<<endl;
    writePageXML(xmlString);
    
    emptyFolder(path);

}//_________________________________
예제 #12
0
파일: himage.c 프로젝트: bowlofstew/ja2
HIMAGE CreateImage( SGPFILENAME ImageFile, UINT16 fContents )
{
	HIMAGE			hImage = NULL;
	SGPFILENAME	Extension;
	CHAR8				ExtensionSep[] = ".";
	STR					StrPtr;
	UINT32			iFileLoader;

	// Depending on extension of filename, use different image readers
	// Get extension
	StrPtr = strstr( ImageFile, ExtensionSep );

	if ( StrPtr == NULL )
	{
		// No extension given, use default internal loader extension
		DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_2, "No extension given, using default" );
		strcat( ImageFile, ".PCX" );
		strcpy( Extension, ".PCX" );
	}
	else
	{
		strcpy( Extension, StrPtr+1 );
	}

	// Determine type from Extension
	do
	{
		iFileLoader = UNKNOWN_FILE_READER;
 
		if ( _stricmp( Extension, "PCX" ) == 0 )
		{
			iFileLoader = PCX_FILE_READER;
			break;
		}

		if ( _stricmp( Extension, "TGA" ) == 0 )
		{
			iFileLoader = TGA_FILE_READER;
			break;
		}

		if ( _stricmp( Extension, "STI" ) == 0 )
		{
			iFileLoader = STCI_FILE_READER;
			break;
		}

	} while ( FALSE );

	// Determine if resource exists before creating image structure
	if ( !FileExists( ImageFile ) )
	{
		//If in debig, make fatal!
#ifdef JA2
#ifdef _DEBUG
		//FatalError( "Resource file %s does not exist.", ImageFile );
#endif
#endif
		DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_2, String("Resource file %s does not exist.", ImageFile) );
		return( NULL );
	}

	// Create memory for image structure
	hImage = (HIMAGE)MemAlloc( sizeof( image_type ) );

	AssertMsg( hImage, "Failed to allocate memory for hImage in CreateImage");
	// Initialize some values
	memset( hImage, 0, sizeof( image_type ) );
		
	//hImage->fFlags = 0;
	// Set data pointers to NULL
	//hImage->pImageData = NULL;
	//hImage->pPalette   = NULL;
	//hImage->pui16BPPPalette = NULL;

	// Set filename and loader
	strcpy( hImage->ImageFile, ImageFile );
	hImage->iFileLoader = iFileLoader;

	if ( !LoadImageData( hImage, fContents ) )
	{
		return( NULL );
	}

	// All is fine, image is loaded and allocated, return pointer
	return( hImage );

}