在这些日子里,我正在使用ARToolKit,我面临着从静态图像创建AR Marker的必要性。因此,正如旧的ARToolKit新闻简报中所建议的那样,我开始编写自己的视频函数,在执行mk_patt.exe时应该替换标准的Win32DirectShow函数。我的视频功能具有以下结构:
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时,它会崩溃。 我需要一些关于如何编码的帮助,或者这是达到我目的的正确方法。
答案 0 :(得分: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();
}