Exemple #1
0
/* Each function wrapper should call this function first */
int isMCRrunning(){
    
    int result;
    
    if(MCRrunning){
        /*We have already initialized the MCR and initialized the MATLAB library DLL in a previous call */
        return true;
    }
    else{
        /* Start the MCR */
        mclmcrInitialize();
        result = mclInitializeApplication(NULL, 0);
        
        if (!result){
            printf("Failed to initialize MCR\n");
            return result;
        }
        
        /* Initialize the MATLAB generated DLL */
        result = lib_summInitialize();
        if(!result){
            printf("Failed to initialize Library\n");
            return result;
        }
        else{
            MCRrunning=1;
            return result;
        }
    }
    
}
Exemple #2
0
int main (int argc, char** argv)
{
	if(!mclInitializeApplication(NULL,0))
	{
		std::cerr << "アプリケーションを初期化できません" << std::endl;
		mclGetLastErrorMessage();
		return -1;
	}
  RTC::Manager* manager;
  manager = RTC::Manager::init(argc, argv);

  // Initialize manager
  manager->init(argc, argv);

  // Set module initialization proceduer
  // This procedure will be invoked in activateManager() function.
  manager->setModuleInitProc(MyModuleInit);

  // Activate manager and register to naming service
  manager->activateManager();

  // run the manager in blocking mode
  // runManager(false) is the default.
  manager->runManager();

  // If you want to run the manager in non-blocking mode, do like this
  // manager->runManager(true);
  mclTerminateApplication();
  return 0;
}
Exemple #3
0
void *run_main( void *in )
{
    mxArray *N;    /* Matrix containing n. */
    mxArray *R = NULL;    /* Result matrix. */
    int      n;    /* Integer parameter from command line. */

    seterr(0); /*reset the error code */
    /* Get any command line parameter. */
    if (((inputs*)in)->ac >= 2) {
        n = atoi(((inputs*)in)->av[1]);
    } else {
        n = 12;
    }

    /* Call the mclInitializeApplication routine. Make sure that the application
     * was initialized properly by checking the return status. This initialization
     * has to be done before calling any MATLAB API's or MATLAB Compiler generated
     * shared library functions. */
    if( !mclInitializeApplication(NULL,0) )
    {
        fprintf(stderr, "Could not initialize the application.\n");
        seterr(-2);
	return in;
    }
    /* Call the library intialization routine and make sure that the
     * library was initialized properly */
    if (!libPkgInitialize())
    {
      fprintf(stderr,"Could not initialize the library.\n");
      seterr(-3);
    }
    else
    {
	/* Create a 1-by-1 matrix containing n. */
        N = mxCreateScalarDouble(n);
      
	/* Call mlfMrank, the compiled version of mrank.m. */
	mlfMrank(1, &R, N);
	
	/* Print the results. */
	mlfPrintmatrix(R);
	
	/* Free the matrices allocated during this computation. */
	mxDestroyArray(N);
	mxDestroyArray(R);
	
	libPkgTerminate();    /* Terminate the library of M-functions */
    }
/* On MAC, you need to call mclSetExitCode with the appropriate exit status
 * Also, note that you should call mclTerminate application in the end of
 * your application. mclTerminateApplication terminates the entire 
 * application and exits with the exit code set using mclSetExitCode. Note
 * that this behavior is only on MAC platform.
 */
#ifdef __APPLE_CC__
    mclSetExitCode(((inputs*)in)->err);
#endif
    mclTerminateApplication();
    return in;
}
int main(int argc, const char **argv)
{
  if (!mclInitializeApplication(
    __MCC_gj_main_component_data.runtime_options,
    __MCC_gj_main_component_data.runtime_option_count))
    return 0;
  
  return mclRunMain(run_main, argc, argv);
}
Exemple #5
0
int main(int argc, const char **argv)
{
#ifndef NOTRANSFORMPROCESSTYPE
  ProcessSerialNumber psn = { 0, kCurrentProcess };
  OSStatus returnCode = TransformProcessType(& psn, kProcessTransformToForegroundApplication);
  if (returnCode) return 0;
#endif
  if (!mclInitializeApplication(
    __MCC_lightTest_component_data.runtime_options, 
    __MCC_lightTest_component_data.runtime_option_count))
    return 0;

  return mclRunMain(run_main, argc, argv);
}
int main(int argc, const char **argv)
{
    int _retval;
    if (!mclInitializeApplication(__MCC_APIT_random_nonoise_mcr_application_options,
                                  __MCC_APIT_random_nonoise_mcr_application_option_count))
        return 0;
    
    if (!APIT_random_nonoiseInitialize())
        return -1;
    _retval = mclMain(_mcr_inst, argc, argv, "apit_random_nonoise", 0);
    if (_retval == 0 /* no error */) mclWaitForFiguresToDie(NULL);
    APIT_random_nonoiseTerminate();
    mclTerminateApplication();
    return _retval;
}
void MatlabInitializationOp::initialize(Beagle::System& ioSystem) {
#ifndef DEBUG_NOMATLAB
	if(!mIsInitialized) {
		// Call application and library initialization. Perform this 
		// initialization before calling any API functions or
		// Compiler-generated libraries.
		const char *pStrings[]={"-nojvm","-nojit"};
		if (!mclInitializeApplication(pStrings,2) || !libAnalogFilterDesignEvalInitialize())
		{
			throw std::runtime_error("Could not initialize the Matlab library properly\n");
		}
		mIsInitialized = true;
	}
#endif
}
Exemple #8
0
int main() {
	/* Initialize the MATLAB Compiler Runtime global state */
	if (!mclInitializeApplication(NULL,0)) {
		fprintf(stderr,  "Could not initialize the MATLAB runtime properly.\n" );
		exit(EXIT_FAILURE);
	}
	if( !liborion3matInitialize() ) {
		fprintf(stderr,  "Could not initialize liborion3mat properly.\n" );
		exit(EXIT_FAILURE);
	}
	char* path_to_input = "test-data/DIADEM/NPF/Input_NPF023_D.txt";
	mxArray* path_to_input_mx = mxCreateString( path_to_input ); /* allocate */
	mlfORION3(path_to_input_mx);
	mxDestroyArray(path_to_input_mx); /* free */
	return 0;
}
Exemple #9
0
int main(int argc, char *argv[])
{
	LibInitializer init;

	QtSingleApplication app(argc, argv);

	QApplication::setOrganizationName("quenii");
	QApplication::setOrganizationDomain("quenii.com");
	QApplication::setApplicationName("ADC-Analyzer-4x");

	REGISTER_METATYPE_HELPER(SignalSettings);
	REGISTER_METATYPE_HELPER(StaticTestSettings);
	REGISTER_METATYPE_HELPER(RegAccessSettings);
	REGISTER_METATYPE_HELPER(SpanSettings);
	REGISTER_METATYPE_HELPER(AdcTypeSettings);
	REGISTER_METATYPE_HELPER(DdsSettings);

#ifdef MATLAB
	if (!(mclInitializeApplication(NULL, 0) && libalgoInitialize()))
	{
		QMessageBox::critical(NULL, "", "Failed to initialize Matlab.");

	}
#endif // MATLAB

	MainWindow w;

	bool ok = app.connect(&app, SIGNAL(messageReceived(const QString &)), &app, SLOT(activateWindow()));
	Q_ASSERT(ok);

	app.setActivationWindow(&w);
	if (app.isRunning())
		return !app.sendMessage(" ");

	w.showMaximized();
	
	int ret = app.exec();

#ifdef MATLAB
	libalgoTerminate();
	mclTerminateApplication();
#endif // MATLAB
	
	return ret;
}
Exemple #10
0
/* 主要工作函式 */
void *mainFunction(int *errorCode){
	mxArray *in1, *in2;	/* 定義送到程式庫函式的輸入矩陣 */
	mxArray *out = NULL;	/* 定義程式庫函式的輸出矩陣 */
	double data[] = {1, 3, 5, 2, 4, 6, 0, 8, 9};	/* 測試用的資料 */

	/* 呼叫 mclInitializeApplication() 以確認此應用程式已經被正確地啟始 */
	if(!mclInitializeApplication(NULL, 0)){
		fprintf(stderr, "錯誤:無法啟始應用程式!\n");
		*errorCode=-1;
		return;
	}
	/* 呼叫 matLibInitialize() 以確認 MATLAB編譯器的程式庫已經被正確地啟始 */
	if (!matLibInitialize()){
		fprintf(stderr,"錯誤:無法啟始程式庫!\n");
		*errorCode=-2;
		return;
	}
    
	/* 創造輸入矩陣 */
	in1 = mxCreateDoubleMatrix(3, 3, mxREAL);
	in2 = mxCreateDoubleMatrix(3, 3, mxREAL);
	memcpy(mxGetPr(in1), data, 9*sizeof(double));	/* 將 data 中的資料拷貝至 in1 */
	memcpy(mxGetPr(in2), data, 9*sizeof(double));	/* 將 data 中的資料拷貝至 in2 */
    
        /* 呼叫由 MATLAB 編譯器產生的程式庫 matLib */
	/* 計算矩陣相乘 */
	mlfMyMatMultiply(1, &out, in1, in2);
	printf("矩陣相乘的結果:\n"); matDisplay(out);
	mxDestroyArray(out); out=NULL;	/* 收回配置給 out 的記憶體 */
	/* 計算反矩陣 */
	mlfMyMatInv(1, &out, in1);
	printf("計算反矩陣的結果:\n"); matDisplay(out);
	mxDestroyArray(out); out=NULL;	/* 收回配置給 out 的記憶體 */

	/* 收回配置給 in1 和 in2 的記憶體 */
	mxDestroyArray(in1); in1=NULL;
	mxDestroyArray(in2); in2=NULL;

	/* 呼叫 matLibTerminate() 以終止應用程式庫 */
	matLibTerminate();
	/* 呼叫 mclTerminateApplication() 以終止此應用程式 */
	mclTerminateApplication();
}
void Process_TX(int *fd)
{

	// Initialize the MATLAB Compiler Runtime global state
	if (!mclInitializeApplication(NULL,0)) 
	{
	std::cerr << "Could not initialize the application properly."
	  << std::endl;
	//return -1;
	}

	// Initialize the Vigenere library
	if( !libMEXtestPHYInitialize() )
	{
	std::cerr << "Could not initialize the library properly."
	  << std::endl;
	//return -1;
	}

	// Must declare all MATLAB data types after initializing the 
	// application and the library, or their constructors will fail.
	mwArray result;
	mwArray decimation;
	decimation = mwArray( 20 );
	char *c;

	int k;
	for (k=0;k<100000;k++){
		// Initialization succeeded. Encrypt or decrypt.
		MEXtestPHYTransmit(1,result);
		//c = strdup( mwString( result.ToString() ) );
        	write(fd[1], "HelloFromTX", 11);
	}

	// Shut down the library and the application global state.
	libMEXtestPHYTerminate();
	mclTerminateApplication();
	//mxfree(objSDRuReceiver);
}
Exemple #12
0
void *run_main(void *x)
{
  int *err = x;
    mxArray *in1, *in2; /* Define input parameters */
    mxArray *out = NULL;/* and output parameters to be passed to the library functions */
    
    double data[] = {1,2,3,4,5,6,7,8,9};

    /* Call the mclInitializeApplication routine. Make sure that the application
     * was initialized properly by checking the return status. This initialization
     * has to be done before calling any MATLAB API's or MATLAB Compiler generated
     * shared library functions.  */
    if( !mclInitializeApplication(NULL,0) )
    {
        fprintf(stderr, "Could not initialize the application.\n");
	*err = -1;
        return(x);
    }
    
    /* Create the input data */
    in1 = mxCreateDoubleMatrix(3,3,mxREAL);
    in2 = mxCreateDoubleMatrix(3,3,mxREAL);
    memcpy(mxGetPr(in1), data, 9*sizeof(double));
    memcpy(mxGetPr(in2), data, 9*sizeof(double));
    
    /* Call the library intialization routine and make sure that the
     * library was initialized properly. */
    if (!libmatrixInitialize()){
        fprintf(stderr,"Could not initialize the library.\n");
        *err = -2;
    }
    else
    {
        /* Call the library function */
        mlfAddmatrix(1, &out, in1, in2);
	/* Display the return value of the library function */
	printf("The value of added matrix is:\n");
	display(out);
	/* Destroy the return value since this varaible will be resued in
	 * the next function call. Since we are going to reuse the variable,
	 * we have to set it to NULL. Refer to MATLAB Compiler documentation
	 * for more information on this. */
	mxDestroyArray(out); out=0;
	mlfMultiplymatrix(1, &out, in1, in2);
	printf("The value of the multiplied matrix is:\n");
	display(out);
	mxDestroyArray(out); out=0;
	mlfEigmatrix(1, &out, in1);
	printf("The eigenvalues of the first matrix are:\n");
	display(out);
	mxDestroyArray(out); out=0;
	
	/* Call the library termination routine */
	libmatrixTerminate();
	
	/* Free the memory created */
	mxDestroyArray(in1); in1=0;
	mxDestroyArray(in2); in2 = 0;
    }
/* On MAC, you need to call mclSetExitCode with the appropriate exit status
 * Also, note that you should call mclTerminate application in the end of
 * your application. mclTerminateApplication terminates the entire 
 * application and exits with the exit code set using mclSetExitCode. Note
 * that this behavior is only on MAC platform.
 */
#ifdef __APPLE_CC__
    mclSetExitCode(*err);
#endif
    mclTerminateApplication();
    return 0;
}
Exemple #13
0
 mcr()
 {
     mclInitializeApplication(NULL, 0);
     libnt2_mwInitialize();
 }
Exemple #14
0
/* Call matlab's fmincon */
int matlab_fmincon(
	       double* x,		    /* result: optimum point */
	       double* fval,		    /* result: optimum function value */
               int ndim,		    /* number of dimensions (variables) */
               double (*objfun)(double *),  /* objective function */
	       double* x0,                  /* starting point */
	       int nIneq,		    /* number of linear inequalities */
	       double* A,		    /* linear inequalities A*X <= B*/
	       double* B,		    
	       int nEq,			    /* number of linear equalities */
	       double* Aeq,		    /* linear equalities Aeq*X = B*/
	       double* Beq,
	       bool hasBounds,              /* are there any bounds */ 
	       double* LB,		    /* lower bounds */
	       double* UB,		    /* upper bounds */
	       int nC,			    /* number of constraints */
	       double* (*C)(double *),      /* non linear constraints */
	       int nCeq,		    /* number of equality constraints */
	       double* (*Ceq)(double *)     /* non linear equality constraints */
	      ){

    /** Intialize MCR and library **/
    const char* ops = "-nodesktop";
    /*const char* ops = "";*/
    if (!mclInitializeApplication(&ops, 1)) {
        printf("Error Initializing Application\n");
        return -1;
    }
    if (!liboptimizeInitialize()) {
        printf("Error Initializing Library\n");
        return -1;
    }

    printf("Setting up matlab optimizer for a %i var problem\n",ndim);
    
    /** The objective function **/
    /* Create a numeric datatype large enough to hold a pointer */
    mxArray *of = mxCreateNumericMatrix(1,1,mxUINT64_CLASS,mxREAL);
    
    /* Save the pointer to the objective function as numeric */
    *((mwSize*)mxGetData(of)) = (mwSize) objfun;
    printf("  Objective function set\n");
    
    /** The starting point **/
    mxArray *x0arr = makeArray(x0,ndim,1);
    printf("  Starting point set x0[0]=%f x0[1]=%f\n",x0[0],x0[1]);

    /** linear constraints **/
    mxArray *Aarr = makeArray(A,nIneq,ndim);
    mxArray *Barr = makeArray(B,nIneq,1);
    printf("  %i inequality constraints set\n",nIneq);

    /** linear equality constraints **/
    mxArray *Aeqarr = makeArray(Aeq,nEq,ndim);
    mxArray *Beqarr = makeArray(Beq,nEq,1);
    printf("  %i equality constraints set\n",nEq);
    
    /** variable bounds **/
    int nb = ndim;
    if (!hasBounds) nb = 0;
    mxArray *LBarr = makeArray(LB,nb,1);
    mxArray *UBarr = makeArray(UB,nb,1);
    printf("  %i variable bounds set\n",nb);
    
    /** nonlinear constraints **/
    mxArray *cf;
    mxArray *ncf = makeScalar(nC);
    if (nC > 0) {
	cf = mxCreateNumericMatrix(1,1,mxUINT64_CLASS,mxREAL);
        *((mwSize*)mxGetData(cf)) = (mwSize) C;
    }else{
        cf = mxCreateNumericMatrix(0, 1, mxDOUBLE_CLASS, mxREAL);
    }
    printf("  %i nonlinear constraints set\n",nC);

    /** nonlinear equality constraints **/
    mxArray *ecf;
    mxArray *necf = makeScalar(nCeq);
    if (nCeq > 0) {
	ecf = mxCreateNumericMatrix(1,1,mxUINT64_CLASS,mxREAL);
        *((mwSize*)mxGetData(ecf)) = (mwSize) Ceq;
    }else{
        ecf = mxCreateNumericMatrix(0, 1, mxDOUBLE_CLASS, mxREAL);
    }
    printf("  %i nonlinear equality constraints set\n",nCeq);

    /** Call the matlab function **/
    mxArray *xarr=NULL;
    mxArray *fvalarr=NULL;

    printf("Calling the matlab library\n");
    
    mlfDoOptim(2,&xarr,&fvalarr,of,x0arr,Aarr,Barr,Aeqarr,Beqarr,LBarr,UBarr,ncf,cf,necf,ecf);
    
    printf("Returning results\n");
    
    /** Get/display the results **/
    double* xa = mxGetPr(xarr);
    double* fvala = mxGetPr(fvalarr);
    int i;
    for(i=0;i<ndim;++i) x[i] = xa[i];
    for(i=0;i<1;++i) fval[i] = fvala[i];
    
    printf("Cleaning up\n");

    /** Cleanup **/
    mxDestroyArray(of);
    mxDestroyArray(x0arr);
    mxDestroyArray(Aarr);
    mxDestroyArray(Barr);
    mxDestroyArray(Aeqarr);
    mxDestroyArray(Beqarr);
    mxDestroyArray(LBarr);
    mxDestroyArray(UBarr);
    mxDestroyArray(cf);
    mxDestroyArray(ecf);
    mxDestroyArray(ncf);
    mxDestroyArray(necf);
    mxDestroyArray(xarr);
    mxDestroyArray(fvalarr);
    
    liboptimizeTerminate();
    mclTerminateApplication();
    
    return 0;
}
Exemple #15
0
BOOL CRecorderApp::InitInstance()
{
	

	// InitCommonControlsEx() is required on Windows XP if an application
	// manifest specifies use of ComCtl32.dll version 6 or later to enable
	// visual styles.  Otherwise, any window creation will fail.
	INITCOMMONCONTROLSEX InitCtrls;
	InitCtrls.dwSize = sizeof(InitCtrls);
	// Set this to include all the common control classes you want to use
	// in your application.
	InitCtrls.dwICC = ICC_WIN95_CLASSES;
	InitCommonControlsEx(&InitCtrls);

	CWinApp::InitInstance();


	AfxEnableControlContainer();

	// Create the shell manager, in case the dialog contains
	// any shell tree view or shell list view controls.
	CShellManager *pShellManager = new CShellManager;

	// Standard initialization
	// If you are not using these features and wish to reduce the size
	// of your final executable, you should remove from the following
	// the specific initialization routines you do not need
	// Change the registry key under which our settings are stored
	// TODO: You should modify this string to be something appropriate
	// such as the name of your company or organization
	SetRegistryKey(_T("Local AppWizard-Generated Applications"));
	
	//the Initialization for the call of external dll and lib!!!
	bool res = false,res1=false,res2=false,res3=false;
		res = mclInitializeApplication(NULL,0);
	if (!res)
	{
		AfxMessageBox(_T("��ʼ��Application������"));
	}
	res = InitializeInitialize();
	res1 = TrainingInitialize();
	res2 = IncTrainInitialize();
	res3 = TestSpeechInitialize();
	if (!res||!res1||!res2||!res3)
	{
		AfxMessageBox(_T("��ʼ��Lib������"));
	}

	

	CString sPath;
	GetModuleFileName(NULL,sPath.GetBufferSetLength(MAX_PATH+1),MAX_PATH);
	sPath.ReleaseBuffer();
	int nPos;
	nPos=sPath.ReverseFind ('\\');
	sPath=sPath.Left (nPos);

	CString lpszFile = sPath + "\\SR1.accdb";
	
	//AfxMessageBox(lpszFile);//
	

	CString str;
	str.Format(_T("DSN=%s? DBQ=%s? FIL=MicrosoftAccess? DEFAULTDIR=%s?? "),_T("SRDSN"),lpszFile,sPath);

	int mlen = str.GetLength();
    for (int i=0; i<mlen; i++)
	{
		if (str.GetAt(i) == '?')
			str.SetAt(i,'\0');
	}

  if (FALSE == SQLConfigDataSource(NULL,ODBC_ADD_DSN,_T("Microsoft Access Driver (*.mdb, *.accdb)\0"),str))
		AfxMessageBox(_T("SQLConfigDataSource Failed"));
  
  //seek for the folder,if not exist,create it.
	CString folderName = _T("E:\\Speechdata");
	
	if(!PathIsDirectory(folderName)){
		CreateDirectory(folderName,NULL);
	}
	folderName = _T("E:\\Speechdata\\Test");
	if(!PathIsDirectory(folderName)){
		CreateDirectory(folderName,NULL);
	}
	CFirstPageDlg cfpdlg;
	cfpdlg.DoModal();

	


	// Delete the shell manager created above.
	if (pShellManager != NULL)
	{
		delete pShellManager;
	}

	// Since the dialog has been closed, return FALSE so that we exit the
	//  application, rather than start the application's message pump.

	InitializeTerminate();
	TrainingTerminate();
	IncTrainTerminate();
	TestSpeechTerminate();
	res = mclTerminateApplication();
	if (!res)
	{
		AfxMessageBox(_T("����Application����!"));
	}
	return FALSE;
}
Exemple #16
0
int main(int ac, char *av[])
{
    
    /* Input parameters:
     *
     * iterations: Number of points to draw in the triangle
     * draw: If true, draw the triangle in a figure window before returning.
     */
    mxArray *iterations = NULL, *draw = NULL;

    /* The Sierpinski function returns the X and Y coordinates of the points
     * forming the pattern in the triangle.
     */
    mxArray *x = NULL, *y = NULL;

    /* Default number of iterations */
    int num_points = 7500;

    /* Validate the number of inputs */
    if (ac < 1 || ac > 2)
    {
	fprintf(stderr, "Expecting 0 or 1 input(s). Found %d\n", ac);
	usage(av[0]);
    }

    /* If we have the right number of inputs (1), try to convert the input
     * string to an integer.
     */
    if (ac == 2)
        num_points = atoi(av[1]);

    /* Type check on input argument -- atoi() will fail if the input is
     * not an integer.
     */
    if (num_points == 0)
    {
	fprintf(stderr, "First argument must be an integer.\n");
	usage(av[0]);
    }

    /* Create the input data */
    iterations = mxCreateDoubleScalar(num_points);
    draw = mxCreateLogicalScalar(1);
    
    /* Call the library intialization routine and make sure that the
     * library was initialized properly
     */
    mclInitializeApplication(NULL,0);
    if (!libtriangleInitialize())
    {
        fprintf(stderr,"could not initialize the triangle library properly\n");
        return -1;
    }

    /* Call the library function */
    mlfSierpinski(2, &x, &y, iterations, draw);

    /* Display the return value of the library function */
    printf("Calculated %d points\n", mxGetNumberOfElements(x));

    /* Free the memory used by the return values. */
    mxDestroyArray(x); x=NULL;
    mxDestroyArray(y); y=NULL;

    /* Call the library termination routine */
    libtriangleTerminate();
    
    /* Free the memory used by the input variables */
    mxDestroyArray(iterations); iterations=0;
    mxDestroyArray(draw); draw = 0;

    /* Shut down all MCR instances */
    mclTerminateApplication();

    /* Success */
    return 0;
}
Exemple #17
0
int run_main( int argc, const char** argv ) {
	cvNamedWindow( "Example2", CV_WINDOW_AUTOSIZE );
	CvCapture* capture;
	IplImage* frame;
	IplImage* grayscaleFrame;
	int i;
	size_t dimensions = 4;
	mxArray* bbox = NULL;
	mxArray* source;
	int *bbox_ptr;
	int a, b, c, d, ok;
	double aa, bb, cc, dd;

	if (!mclInitializeApplication(NULL, 0)) {
		fprintf(stderr, "Could not initialize the application\n");
		exit(-1);
	}

	if (!libopentldInitialize()) {
		fprintf(stderr, "Could not initialize libopentld\n");
		exit(-1);
	}

	capture = cvCaptureFromCAM(-1);
	if (capture == NULL) {
		printf("Oooops .. I'm screwed :-(\n");
		exit(-1);
	}

	frame = cvQueryFrame(capture);
	grayscaleFrame = cvCreateImage(cvSize(frame->width, frame->height), IPL_DEPTH_8U, 1);

	printf("frame width: %d, height: %d\n", frame->width, frame->height);

	mlfTldExampleInitDefault();

	while(1) {
		frame = cvQueryFrame( capture );
		if( !frame ) break;

		cvConvertImage(frame, grayscaleFrame, 0);
		cvSaveImage("temp/frame.png", grayscaleFrame);
		mlfTldProcessSingleFrame();


		a = -1, b = -1, c = -1, d = -1;
		aa = -1, bb = -1, cc = -1, dd = -1;
		FILE * f = fopen("bb.txt", "rt");
		if (f != NULL) {
			fscanf(f, "%lf", &aa); a = (int) aa;
			fscanf(f, "%lf", &bb); b = (int) bb;
			fscanf(f, "%lf", &cc); c = (int) cc;
			fscanf(f, "%lf", &dd); d = (int) dd;
			fclose(f);
		}
		ok = (a != -1) && (b != -1) && (c != -1) && (d != -1);
		
		if (ok) {
			printf("a = %d, b = %d, c = %d, d = %d\n", a, b, c,d);
			cvDrawRect(frame, cvPoint(a,b), cvPoint(c,d), cvScalar(255, 0, 0), 2);
		}

		cvShowImage( "Example2", frame );
		char c = cvWaitKey(33);
		if( c == 27 ) break;

	}

	cvReleaseImage(&frame);
	cvReleaseImage(&grayscaleFrame);
	cvReleaseCapture( &capture );
	cvDestroyWindow( "Example2" );

	libopentldTerminate();

	/* Destroy stuff related to Matlab */
	
	mclTerminateApplication();

	return 0;
}
Exemple #18
0
 void GTVideo::snakeTracking2()
 {    
     if(foregroundMask.isEmpty() || abnormallist.isEmpty())
     {
         QMessageBox msgBox;
         msgBox.setText("Video source and initial abnormal range must be set before tracking");
         msgBox.exec();
         return;
     }

     int totalAbnormalCount = getAbnormalFrameCount();
     int currCount = 0;
     QProgressDialog progress("Generating Groundtruth Images...", "Abort", 0, totalAbnormalCount-1);
     progress.setWindowModality(Qt::WindowModal);
     progress.setValue(currCount);

     // Initialize the MATLAB Compiler Runtime global state
     if (!mclInitializeApplication(NULL,0))
     {
         std::cerr << "Could not initialize the application properly."
                   <<  std::endl;
     }
     // Initialize the segmentation library
     if (!libsegInitialize())
     {
         std::cerr << "Could not initialize the library properly."
                   << std::endl;
     }

     //initialize the groundtruth
     cv::Mat eye = foregroundMask.at(0).clone();
     eye.setTo(cv::Scalar(0)); //cv::Scalar(0,0,0)
     grdtruth.fill(eye);

     for (int iAb=0; iAb<abnormallist.size(); iAb++)
     {
         uint start = abnormallist[iAb].getStart();
         uint end = abnormallist[iAb].getEnd();

         const QVector<cv::Point>& boundaryPoints = abnormallist[iAb].getBoundaryPoints();
         const cv::Point *pAddBoundary = boundaryPoints.data();
         const cv::Point **pBoundaryPoints = &pAddBoundary;

         // initialize the segmentation mask
         cv::Mat initmask = abnormallist[iAb].getROI();

         // set tracked object as abnormal ROI
         for (uint iFrame=start; iFrame<=end; iFrame++)
         {
             currCount++;
             progress.setValue(currCount);
             if(progress.wasCanceled())
             {
                 return;
             }
             else
             {
                 cv::Mat grayFrame(foregroundMask.at(iFrame));
                 // generate groundtruth and update mask using that in previous frame
                 cv::Mat resultImage = segmentByActiveContour(grayFrame, initmask, 200, false);
                 if (NULL == resultImage.data)
                 {
                     qDebug() << QString("No groudtruth generated for frame %1").arg(iFrame);
                     continue;
                 }
                 initmask = resultImage.clone();

                 // set groudtruth result
                 setGroundtruth(resultImage, iFrame);
             }
         }
     }
     progress.setValue(totalAbnormalCount-1);

     mclTerminateApplication();
     libsegTerminate();
 }