bool ARMarkerSquare::initWithPatternFile(const char* path, ARdouble width, ARPattHandle *arPattHandle)
{
	// Ensure the pattern string is valid
	if (!path || !arPattHandle) return false;
    
    if (m_loaded) unload();

	ARController::logv(AR_LOG_LEVEL_INFO, "Loading single AR marker from file '%s', width %f.", path, width);
	
    m_arPattHandle = arPattHandle;
	patt_id = arPattLoad(m_arPattHandle, path);
	if (patt_id < 0) {
		ARController::logv(AR_LOG_LEVEL_ERROR, "Error: unable to load single AR marker from file '%s'.", path);
        arPattHandle = NULL;
		return false;
	}
	
    patt_type = AR_PATTERN_TYPE_TEMPLATE;
    m_width = width;
    
	visible = visiblePrev = false;
    
    // An ARPattern to hold an image of the pattern for display to the user.
	allocatePatterns(1);
	patterns[0]->loadTemplate(patt_id, m_arPattHandle, (float)m_width);

    m_loaded = true;
	return true;
}
示例#2
0
static int setupMarker(const char *patt_name, int *patt_id, ARHandle *arhandle, ARPattHandle **pattHandle_p)
{	
    if ((*pattHandle_p = arPattCreateHandle()) == NULL) {
        ARLOGe("setupMarker(): Error: arPattCreateHandle.\n");
        return (FALSE);
    }
    
	// Loading only 1 pattern in this example.
	if ((*patt_id = arPattLoad(*pattHandle_p, patt_name)) < 0) {
		ARLOGe("setupMarker(): Error loading pattern file %s.\n", patt_name);
		arPattDeleteHandle(*pattHandle_p);
		return (FALSE);
	}
    
    arPattAttach(arhandle, *pattHandle_p);
	
	return (TRUE);
}
示例#3
0
bool ofxArtool5::setupMarker(string pthMarker){
    const char * cPthMarker = ofToDataPath(pthMarker).c_str();
    
    if((gARPattHandle = arPattCreateHandle())==NULL){
        ofLogError("ofxArtool5::setupMarker()","Error arPattCreateHandle");
        return false;
    }
    
    if((pattId = arPattLoad(gARPattHandle, cPthMarker))<0){
        ofLogError("ofxArtool5::setupMarker()","Error arPattLoad");
        arPattDeleteHandle(gARPattHandle);
        return false;
    }
    
    arPattAttach(gARHandle, gARPattHandle);
    
    return true;
}
示例#4
0
static void   init(int argc, char *argv[])
{
    ARParam         cparam;
    ARGViewport     viewport;
    ARPattHandle    *arPattHandle;
    char            vconf[512];
    AR_PIXEL_FORMAT pixFormat;
    ARUint32        id0, id1;
    int             i;

    if (argc == 1)
        vconf[0] = '\0';
    else
    {
        strcpy(vconf, argv[1]);

        for (i = 2; i < argc; i++)
        {
            strcat(vconf, " "); strcat(vconf, argv[i]);
        }
    }

    /* open the video path */
    if (arVideoOpen(vconf) < 0)
        exit(0);

    if (arVideoGetSize(&xsize, &ysize) < 0)
        exit(0);

    ARLOG("Image size (x,y) = (%d,%d)\n", xsize, ysize);
    if ((pixFormat = arVideoGetPixelFormat()) < 0)
        exit(0);

    if (arVideoGetId(&id0, &id1) == 0)
    {
        ARLOG("Camera ID = (%08x, %08x)\n", id1, id0);
        sprintf(vconf, VPARA_NAME, id1, id0);
        if (arVideoLoadParam(vconf) < 0)
        {
            ARLOGe("No camera setting data!!\n");
        }
    }

    /* set the initial camera parameters */
    if (arParamLoad(CPARA_NAME, 1, &cparam) < 0)
    {
        ARLOGe("Camera parameter load error !!\n");
        exit(0);
    }

    arParamChangeSize(&cparam, xsize, ysize, &cparam);
    ARLOG("*** Camera Parameter ***\n");
    arParamDisp(&cparam);
    if ((gCparamLT = arParamLTCreate(&cparam, AR_PARAM_LT_DEFAULT_OFFSET)) == NULL)
    {
        ARLOGe("Error: arParamLTCreate.\n");
        exit(-1);
    }

    if ((arHandle = arCreateHandle(gCparamLT)) == NULL)
    {
        ARLOGe("Error: arCreateHandle.\n");
        exit(0);
    }

    if (arSetPixelFormat(arHandle, pixFormat) < 0)
    {
        ARLOGe("Error: arSetPixelFormat.\n");
        exit(0);
    }

    if ((ar3DHandle = ar3DCreateHandle(&cparam)) == NULL)
    {
        ARLOGe("Error: ar3DCreateHandle.\n");
        exit(0);
    }

    if ((arPattHandle = arPattCreateHandle()) == NULL)
    {
        ARLOGe("Error: arPattCreateHandle.\n");
        exit(0);
    }

    if ((patt_id = arPattLoad(arPattHandle, PATT_NAME)) < 0)
    {
        ARLOGe("pattern load error !!\n");
        exit(0);
    }

    arPattAttach(arHandle, arPattHandle);

    /* open the graphics window */
    w1             = argCreateWindow(xsize, ysize);
    viewport.sx    = 0;
    viewport.sy    = 0;
    viewport.xsize = xsize;
    viewport.ysize = ysize;
    if ((vp1 = argCreateViewport(&viewport)) == NULL)
        exit(0);

    argViewportSetCparam(vp1, &cparam);
    argViewportSetPixFormat(vp1, pixFormat);
    argViewportSetDispMethod(vp1, AR_GL_DISP_METHOD_TEXTURE_MAPPING_FRAME);
    argViewportSetDispMode(vp1, AR_GL_DISP_MODE_FIT_TO_VIEWPORT);
    argViewportSetDistortionMode(vp1, AR_GL_DISTORTION_COMPENSATE_ENABLE);

    w2             = argCreateWindow(xsize, ysize);
    viewport.sx    = 0;
    viewport.sy    = 0;
    viewport.xsize = xsize;
    viewport.ysize = ysize;
    if ((vp2 = argCreateViewport(&viewport)) == NULL)
        exit(0);

    argViewportSetCparam(vp2, &cparam);
    argViewportSetPixFormat(vp2, pixFormat);
    argViewportSetDispMethod(vp2, AR_GL_DISP_METHOD_TEXTURE_MAPPING_FRAME);
    argViewportSetDispMode(vp2, AR_GL_DISP_MODE_FIT_TO_VIEWPORT);
    argViewportSetDistortionMode(vp2, AR_GL_DISTORTION_COMPENSATE_DISABLE);

    return;
}
示例#5
0
AR2MarkerSetT* ar2ReadMarkerSet(char *filename, char *ext, ARPattHandle  *pattHandle)
{
    // COVHI10394
    FILE          *fp        = NULL;
    AR2MarkerSetT *markerSet = NULL;
    char          buf[256], buf1[256] /*, buf2[256]*/;
    int           i, j;

    char namebuf[512];

    sprintf(namebuf, "%s.%s", filename, ext);
    if ((fp = fopen(namebuf, "r")) == NULL)
        return NULL;

    arMalloc(markerSet, AR2MarkerSetT, 1);

    if (get_buff(buf, 256, fp) == NULL)
    {
        free(markerSet);
        markerSet = NULL;
        goto done;
    }

    if (sscanf(buf, "%d", &(markerSet->num)) != 1)
    {
        free(markerSet);
        markerSet = NULL;
        goto done;
    }

    if (markerSet->num <= 0)
    {
        free(markerSet);
        markerSet = NULL;
        goto done;
    }

    arMalloc(markerSet->marker, AR2MarkerT, markerSet->num);

    for (i = 0; i < markerSet->num; i++)
    {
        if (get_buff(buf, 256, fp) == NULL)
        {
            free(markerSet->marker);
            free(markerSet);
            markerSet = NULL;
            goto done;
        }

        if (sscanf(buf, "%s", buf1) != 1)
        {
            free(markerSet->marker);
            free(markerSet);
            markerSet = NULL;
            goto done;
        }

        // ar2UtilDivideExt(buf1, buf, buf2);
        if ((markerSet->marker[i].pattId = arPattLoad(pattHandle, buf1)) < 0)
        {
            free(markerSet->marker);
            free(markerSet);
            markerSet = NULL;
            goto done;
        }

        if (get_buff(buf, 256, fp) == NULL)
        {
            free(markerSet->marker);
            free(markerSet);
            markerSet = NULL;
            goto done;
        }

        if (sscanf(buf, "%f", &(markerSet->marker[i].width)) != 1)
        {
            free(markerSet->marker);
            free(markerSet);
            markerSet = NULL;
            goto done;
        }

        for (j = 0; j < 3; j++)
        {
            if (get_buff(buf, 256, fp) == NULL)
            {
                free(markerSet->marker);
                free(markerSet);
                markerSet = NULL;
                goto done;
            }

            if (sscanf(buf, "%f %f %f %f",
                       &(markerSet->marker[i].transI2M[j][0]),
                       &(markerSet->marker[i].transI2M[j][1]),
                       &(markerSet->marker[i].transI2M[j][2]),
                       &(markerSet->marker[i].transI2M[j][3])) != 4)
            {
                free(markerSet->marker);
                free(markerSet);
                markerSet = NULL;
                goto done;
            }
        }
    }

done:
    fclose(fp);
    return markerSet;
}
ARMultiMarkerInfoT *arMultiReadConfigFile( const char *filename, ARPattHandle *pattHandle )
{
    FILE                   *fp;
    ARMultiEachMarkerInfoT *marker;
    ARMultiMarkerInfoT     *marker_info;
    ARdouble               wpos3d[4][2];
    char                   buf[256], pattPath[2048], dummy;
    int                    num;
    int                    patt_type = 0;
    int                    i, j;

    if ((fp = fopen(filename, "r")) == NULL) {
        ARLOGe("Error: unable to open multimarker config file '%s'.\n", filename);
        ARLOGperror(NULL);
        return NULL;
    }

    get_buff(buf, 256, fp);
    if( sscanf(buf, "%d", &num) != 1 ) {
        ARLOGe("Error processing multimarker config file '%s': First line must be number of marker configs to read.\n", filename);
        fclose(fp);
        return NULL;
    }
    ARLOGd("Reading %d markers from multimarker file '%s'\n", num, filename);

    arMalloc(marker, ARMultiEachMarkerInfoT, num);

    for( i = 0; i < num; i++ ) {
        get_buff(buf, 256, fp);
        if (sscanf(buf, 
#if defined(__LP64__) && !defined(__APPLE__)
                        "%lu%c",
#else
                        "%llu%c",
#endif
                         &(marker[i].globalID), &dummy) != 1) { // Try first as matrix code.
            
            if (!pattHandle) {
                ARLOGe("Error processing multimarker config file '%s': pattern '%s' specified in multimarker configuration while in barcode-only mode.\n", filename, buf);
                goto bail;
            }
            if (!arUtilGetDirectoryNameFromPath(pattPath, filename, sizeof(pattPath), 1)) { // Get directory prefix.
                ARLOGe("Error processing multimarker config file '%s': Unable to determine directory name.\n", filename);
                goto bail;
            }
            strncat(pattPath, buf, sizeof(pattPath) - strlen(pattPath) - 1); // Add name of file to open.
            if ((marker[i].patt_id = arPattLoad(pattHandle, pattPath)) < 0) {
                ARLOGe("Error processing multimarker config file '%s': Unable to load pattern '%s'.\n", filename, pattPath);
                goto bail;
            }
            marker[i].patt_type = AR_MULTI_PATTERN_TYPE_TEMPLATE;
            patt_type |= 0x01;
        } else {
            
            if ((marker[i].globalID & 0xffff8000ULL) == 0ULL) marker[i].patt_id = (int)(marker[i].globalID & 0x00007fffULL); // If upper 33 bits are zero, use lower 31 bits as regular matrix code.
            else marker[i].patt_id = 0;
            ARLOGd("Marker %3d is matrix code %llu.\n", i + 1, marker[i].globalID);
            marker[i].patt_type = AR_MULTI_PATTERN_TYPE_MATRIX;
            patt_type |= 0x02;
        }

        get_buff(buf, 256, fp);
        if( sscanf(buf,
#ifdef ARDOUBLE_IS_FLOAT
                   "%f",
#else
                   "%lf",
#endif
                   &marker[i].width) != 1 ) {
            ARLOGe("Error processing multimarker config file '%s', marker definition %3d: First line must be pattern width.\n", filename, i + 1);
            goto bail;
        }
        
        j = 0;
        get_buff(buf, 256, fp);
        if( sscanf(buf,
#ifdef ARDOUBLE_IS_FLOAT
                   "%f %f %f %f",
#else
                   "%lf %lf %lf %lf",
#endif
                   &marker[i].trans[j][0],
                   &marker[i].trans[j][1],
                   &marker[i].trans[j][2],
                   &marker[i].trans[j][3]) != 4 ) {
            // Perhaps this is an old ARToolKit v2.x multimarker file?
            // If so, then the next line is two values (center) and should be skipped.
            float t1, t2;
            if( sscanf(buf,
                       "%f %f",
                       &t1, &t2) != 2 ) {
                ARLOGe("Error processing multimarker config file '%s', marker definition %3d: Lines 2 - 4 must be marker transform.\n", filename, i + 1);
                goto bail;
            }
        } else j++;
        do {
            get_buff(buf, 256, fp);
            if( sscanf(buf, 
#ifdef ARDOUBLE_IS_FLOAT
                       "%f %f %f %f",
#else
                       "%lf %lf %lf %lf",
#endif
                       &marker[i].trans[j][0],
                       &marker[i].trans[j][1],
                       &marker[i].trans[j][2],
                       &marker[i].trans[j][3]) != 4 ) {
                ARLOGe("Error processing multimarker config file '%s', marker definition %3d: Lines 2 - 4 must be marker transform.\n", filename, i + 1);
                goto bail;
            }
            j++;
        } while (j < 3);
        arUtilMatInv( (const ARdouble (*)[4])marker[i].trans, marker[i].itrans );

        wpos3d[0][0] =  -marker[i].width/2.0;
        wpos3d[0][1] =   marker[i].width/2.0;
        wpos3d[1][0] =   marker[i].width/2.0;
        wpos3d[1][1] =   marker[i].width/2.0;
        wpos3d[2][0] =   marker[i].width/2.0;
        wpos3d[2][1] =  -marker[i].width/2.0;
        wpos3d[3][0] =  -marker[i].width/2.0;
        wpos3d[3][1] =  -marker[i].width/2.0;
        for( j = 0; j < 4; j++ ) {
            marker[i].pos3d[j][0] = marker[i].trans[0][0] * wpos3d[j][0]
                                  + marker[i].trans[0][1] * wpos3d[j][1]
                                  + marker[i].trans[0][3];
            marker[i].pos3d[j][1] = marker[i].trans[1][0] * wpos3d[j][0]
                                  + marker[i].trans[1][1] * wpos3d[j][1]
                                  + marker[i].trans[1][3];
            marker[i].pos3d[j][2] = marker[i].trans[2][0] * wpos3d[j][0]
                                  + marker[i].trans[2][1] * wpos3d[j][1]
                                  + marker[i].trans[2][3];
        }
    }

    fclose(fp);

    arMalloc(marker_info, ARMultiMarkerInfoT, 1);
    marker_info->marker     = marker;
    marker_info->marker_num = num;
    marker_info->prevF      = 0;
    if( (patt_type & 0x03) == 0x03 ) marker_info->patt_type = AR_MULTI_PATTERN_DETECTION_MODE_TEMPLATE_AND_MATRIX;
    else if( patt_type & 0x01 )    marker_info->patt_type = AR_MULTI_PATTERN_DETECTION_MODE_TEMPLATE;
    else                           marker_info->patt_type = AR_MULTI_PATTERN_DETECTION_MODE_MATRIX;
    marker_info->cfPattCutoff = AR_MULTI_CONFIDENCE_PATTERN_CUTOFF_DEFAULT;
    marker_info->cfMatrixCutoff = AR_MULTI_CONFIDENCE_MATRIX_CUTOFF_DEFAULT;

    return marker_info;
    
bail:
    fclose(fp);
    free(marker);
    return NULL;
}