2012-08-14 31 views
1

在這些日子裏,我正在使用ARToolKit,並且我面臨從靜態圖像創建AR標記的必要性。因此,正如在舊版ARToolKit的新聞通訊中所建議的那樣,我開始編寫自己的視頻功能,它應該在執行mk_patt.exe時替代標準的Win32DirectShow功能。我的視頻功能有後續的結構:從圖像創建AR標記

int arVideoOpen(char *config) { 
    return 0; 
} 

int arVideoClose(void){ 
    return 0; 
} 

int arVideoDispOption(void){ 
    return 0; 
}  

int arVideoInqSize(int *x, int *y){ 
    *x = xsize; 
    *y = ysize; 
} 

ARUint8 *arVideoGetImage(void) 
{ 
    FILE *pFile; 
unsigned long Size; 
unsigned char *buffer; 
size_t result; 

    pFile = fopen("hhgf.bmp","rb"); 
    if(pFile==0){ 
     printf("Error!\n"); 
    } 
    else{ 
     fseek(pFile, 0, SEEK_END); 
     Size = ftell(pFile); 
     printf("Size: %d \n",Size); 
     fseek(pFile, 0, SEEK_SET); 
     buffer = (unsigned char*) malloc (Size); 
     if (buffer == NULL) {fputs ("Memory error",stderr); exit (2);} 
      result = fread (buffer, Size,1, pFile); 
     if (result != Size) {fputs ("Reading error",stderr); } 
     return (ARUint8 *) buffer; 
    } 
} 

int arVideoCapStart(void){ 
    return 0; 
} 

int arVideoCapStop(void) { 
    return 0; 
} 

int arVideoCapNext(void) 
{ 
    return 0; 
} 

焦點方法是arVideoGetImage,它應該返回我的圖像數據。我對C沒有太多的專業知識,所以我在網上找到了一些簡單的代碼,但是當我運行mk_patt.exe時,它崩潰了。 我需要一些關於如何編碼的幫助,或者如果這是達到我的目的的正確方法。

回答

1

我已經解決了這樣的

ARUint8 *getBack(){ 
    int i; 
    unsigned char *buffer; 
    int Size; 
    FILE *streamIn; 
    int byte; 
    int count = 0; 
    //printf("What wath %d \n",AR_DEFAULT_PIXEL_FORMAT); 
    if(!isDef){ 
     image = (int *) malloc(400*400*sizeof(int)); 
     streamIn = fopen("hhgf.bmp", "rb"); 

      fseek(streamIn, 0, SEEK_END); 
      Size = ftell( streamIn); 
      fseek(streamIn, 0, SEEK_SET); 

     if (streamIn == (FILE *)0){ 
      printf("File opening error ocurred. Exiting program.\n"); 
      exit(0); 
     } 


     for(i=0;i<(Size-(400*400));i++) byte= getc(streamIn); 
     i=0; 
     while((count=getc(streamIn))!=-1){ 
      image[i]=count; 
      i++; 
     } 

     fclose(streamIn); 

     isDef=true; 
    } 

    return (ARUint8 *)image; 
} 


ARUint8 *arVideoGetImage(void){ 
      return getBack(); 
}