Example #1
0
void displayLS(LinearSystemProblem* p)
{
  printf("Numerics LinearSystem DISPLAY:\n-------------\n");
  if (!p)
  {
    printf("p is null \n");
    return;
  }
  int size = p->size;

  printf("size :%d \n", size);
  if (p->M)
  {
    printf("M matrix:\n");
    displayMat(p->M->matrix0, size, size, size);
  }
  else
    printf("No M matrix:\n");
  if (p->q)
  {
    printf("q matrix:\n");
    displayMat(p->q, size, 1, 0);
  }
  else
    printf("No q:\n");

}
Example #2
0
void MainWindow::processColorDetection()
{
    ColorDetectController::getInstance()->setColorDistanceThreshold(ui->verticalSlider_Threshold->value());
    ColorDetectController::getInstance()->process();

    cv::Mat resulting = ColorDetectController::getInstance()->getLastResult();
    if (!resulting.empty())
        displayMat(resulting);

}
Example #3
0
void display(const NumericsMatrix* const m)
{
    if (! m)
    {
        fprintf(stderr, "Numerics, NumericsMatrix display failed, NULL input.\n");
        exit(EXIT_FAILURE);
    }
    printf("\n ========== Numerics Matrix\n");
    printf("\n ========== storageType = %i\n", m->storageType);

    switch (m->storageType)
    {
    case NM_DENSE:
    {

        displayMat(m->matrix0, m->size0, m->size1, m->size0);
        break;
    }
    case NM_SPARSE_BLOCK:
    {
        assert(m->matrix1);
        printSBM(m->matrix1);
        break;
    }
    case NM_SPARSE:
    {
        assert(m->matrix2);
        if (m->matrix2->triplet)
        {
            cs_print(m->matrix2->triplet, 0);
        }
        else if (m->matrix2->csc)
        {
            cs_print(m->matrix2->csc, 0);
        }
        else if (m->matrix2->trans_csc)
        {
            cs_print(m->matrix2->trans_csc, 0);
        }
        else
        {
            fprintf(stderr, "display for sparse matrix: no matrix found!\n");
        }
        break;
    }
    default:
    {
        fprintf(stderr, "display for NumericsMatrix: matrix type %d not supported!\n", m->storageType);
    }
    }
}
void MainWindow::workOnNextImage() {
    if(!pause && runCam) {
        // Try to take a picture
        bool gotPicture = takePicture();
        if(gotPicture) {
            displayMat(currentFrame, *ui->imDisplay1);
            processImage();
        }
        else {
            // We couldn't get the next picture, so stop processing
            qWarning("Stopped processing. Please choose a new file or restart the camera.");
            runCam = false;
        }
    }
}
Example #5
0
void MainWindow::setImage()
{
    QFileDialog::Options options;
    QString selectedFilter;
    QString fileName = QFileDialog::getOpenFileName(this,
                                tr("Open Image Files"),
                                "",
                                tr("Image files (*.jpg *.jpeg *.png *.gif *.bmp)"),
                                &selectedFilter,
                                options);
    if (!fileName.isEmpty()){
        cv::Mat img_mat = cv::imread(fileName.toStdString(),1); //0 for grayscale
        displayMat(img_mat);
    }
    //Set Filename
    ColorDetectController::getInstance()->setInputImage(fileName.toStdString());
}
Example #6
0
int main(int argc, char **argv){
	int** mat_a;
	int** mat_b;
	int** mat_c;
	int rows_mat_a, cols_mat_a, rows_mat_b, cols_mat_b;
	int i;
	
	if(argc < 3){
		printf("matmult.out matrix_A_File matrix_B_File\n");
		printf("Not enough arguments given.n");
		return(1);
	}
	
	//read in matrices
	readMat(argv[1], &mat_a, &rows_mat_a, &cols_mat_a);
	readMat(argv[2], &mat_b, &rows_mat_b, &cols_mat_b);
	
	//do the multiplication
	mat_c = matMult(mat_a, rows_mat_a, cols_mat_a, mat_b, rows_mat_b, cols_mat_b);
	
	//display solution
	displayMat(mat_c, rows_mat_a, cols_mat_b);
	
	//free up malloced space
	for(i = 0; i < rows_mat_a; i++){
		free(mat_a[i]);
	}
	
	for(i = 0; i < rows_mat_b; i++){
		free(mat_b[i]);
	}
	
	for(i = 0; i < rows_mat_a; i++){
		free(mat_c[i]);
	}

	free(mat_a);
	free(mat_b);
	free(mat_c);
	
	return 0;
}//main
void GestureDetector::updateTimer()
{
	timeCount = (timeCount + DELAY) % RECINT; //increment counter on a cycle
	warnCount = (warnCount + DELAY) % WARNINT; //do same with the warning count
	cv::Mat image, filtered;
    cap >> image;

	//set the image from the camera, process it and get filtered
	SkinDetectController::getInstance()->setInputImage(image);
	SkinDetectController::getInstance()->process();
	filtered = SkinDetectController::getInstance()->getLastResult(); //binary image of blobs

	//retrieve the hand gestures from the image from the image
	std::vector<Hand> hands = detect(image, filtered);

	if(timeCount < DELAY)
	{ // Only store the hands when the timeCount
		//rolls over after iterating to the record
		//interval (RECINT)

		pw.addHandSet(hands);

		imageCache.push_back(image.clone());

		//print out the captured hands
		if(hands.size() > 1)
			ui->textEdit->append(hands[0].toQString()
						 + "\n  and: " + hands[1].toQString());
		else
			ui->textEdit->append(hands[0].toQString());

	
	    // Determine if it is time to check the password
	    if(pw.doCheck(hands))
	    {
			if(pw.checkPassword())
				ui->textEdit->append("----------------------\n"
	                                "PASSWORD ACCEPTED!!!!!!\n"
	                                "----------------------");
			else
	            ui->textEdit->append("----------------------\n"
	                                "INTRUDER... INTRUDER....\n"
	                                "----------------------");

	        char filename[200];
	        //record pictures for documentation
	        for(int i = 0; i < imageCache.size(); i++)
	        {
	        	sprintf(filename, "%s_%d_%d.jpg", DESKTOP, setCount, i);
                cvSaveImage(filename, &(IplImage(imageCache[i])));
            }


			pw.reset();
			setCount++;
			imageCache.clear();
	     }
	}

	// warn the user of the time to capture
	// ticks down from WARNMAX to capture
	if(warnCount < DELAY)
	{
		int timeLeft = WARNMAX - timeCount/WARNINT;
		if(timeLeft == WARNMAX)
			ui->textEdit->append("\n\nPREPARE FOR CAPTURE IN....");
		ui->textEdit->append(QString("%1...........").arg(timeLeft));
	}
	
	// display the processed image
	displayMat(image);
}
int main(int argc, const char *argv[])
{
    // Seed the random number generator using time
    srand48((unsigned int) time(NULL));

    // Dimension of the operation with defaul value
    int N = PROBSIZE;

    // Specify operation: 0 MatMult; 1 MatVecMult
    int opr = 0;

    // Whether to verify the result or not
    int verif = 0;

    // Whether to display the result or not
    int disp = 0;

    // Whether to call the naive implementation
    int execNaive = 1;

    // Whether to call the optimized implementation
    int execOPT = 1;

    // Parse command line
    {
        int arg_index = 1;
        int print_usage = 0;

        while (arg_index < argc)
        {
            if ( strcmp(argv[arg_index], "-N") == 0 )
            {
                arg_index++;
                N = atoi(argv[arg_index++]);
            }
            else if ( strcmp(argv[arg_index], "-operation") == 0 )
            {
                arg_index++;
                opr = atoi(argv[arg_index++]);
            }
            else if ( strcmp(argv[arg_index], "-help") == 0 )
            {
                print_usage = 1;
                break;
            }
            else if( strcmp(argv[arg_index], "-verif") == 0 )
            {
                arg_index++;
                verif = 1;
                if(execNaive==0 || execOPT==0) {
                  printf("***Must call both naive and optimized when running verification\n");
                  print_usage = 1;
                  break;
                }
            }
            else if( strcmp(argv[arg_index], "-disp") == 0 )
            {
                arg_index++;
                disp = 1;
            }
            else if( strcmp(argv[arg_index], "-naive") == 0 )
            {
                arg_index++;
                execNaive = 1;
                execOPT   = 0;
                if(verif==1) {
                  printf("***Must call both naive and optimized when running verification\n");
                  print_usage = 1;
                  break;                  
                }
            }
            else if( strcmp(argv[arg_index], "-OPT") == 0 )
            {
                arg_index++;
                execOPT   = 1;
                execNaive = 0;
                if(verif==1) {
                  printf("***Must call both naive and optimized when running verification\n");
                  print_usage = 1;
                  break;                  
                }
            }
            else
            {
                printf("***Invalid argument: %s\n", argv[arg_index]);
                print_usage = 1;
                break;
            }
        }

        if (print_usage)
        {
            printf("\n");
            printf("Usage: %s [<options>]\n", argv[0]);
            printf("\n");
            printf("  -N <N>          : problem size (default: %d)\n", PROBSIZE);
            printf("  -operation <ID> : Operation ID = 0 for MatMult or ID = 1 for MatVecMult\n");
            printf("  -verif          : Activate verification\n");
            printf("  -disp           : Display result (use only for small N!)\n");
            printf("  -naive          : Run only naive implementation\n");
            printf("  -OPT            : Run only optimized implementation\n");
            printf("  -help           : Display this message\n");
            printf("\n");
        }

        if (print_usage)
            return 0;
    }

    // Perform operation
    switch(opr)
    {
        case 0: /* Matrix-matrix multiply */
            {
                printf("Performing matrix-matrix multiply operation\n");
                double *matA, *matB, *matC1, *matC2;

                // Allocate memory
                matA = (double *) malloc(N*N * sizeof(double));
                matB = (double *) malloc(N*N * sizeof(double));
                if(execNaive) matC1 = (double *) malloc(N*N * sizeof(double));
                if(execOPT)   matC2 = (double *) malloc(N*N * sizeof(double));

                // Initialize matrix values
                randInitialize(N*N,matA);
                randInitialize(N*N,matB);

                clock_t tic, toc;
                double tm;

                if(execNaive) {
                  // Perform naive matA x matB = matC1
                  tic = clock();
                  matMult(N,matA,matB,matC1);
                  toc = clock();
                  tm = (double)(toc - tic) / CLOCKS_PER_SEC;
                  printf("Elapsed time for naive mat-mat mult.: %f seconds\n",tm);
                }

                if(execOPT) {
                  // Perform optimized matA x matB = matC2
                  tic = clock();
                  //matMult_opt(N,matA,matB,matC2);
                  toc = clock();
                  tm = (double)(toc - tic) / CLOCKS_PER_SEC;
                  printf("Elapsed time for optimized mat-mat mult.: %f seconds\n",tm);
                }

                // Verify results (compare the two matrices)
                if(verif)
                    compareVecs(N*N,matC2,matC1);

                // Display results (don't use for large matrices)
                if(disp)
                {
                    displayMat(N,N,matA);
                    printf("\n");
                    displayMat(N,N,matB);
                    printf("\n");
                    displayMat(N,N,matC1);
                    printf("\n");
		    displayMat(N,N,matC2);
                }

                // Free memory
                free(matA);
                free(matB);
                if(execNaive) free(matC1);
                if(execOPT)   free(matC2);
            }
            break;

        case 1: /* Matrix-vector multiply */
            {
                printf("Performing matrix-vector multiply operation\n");
                double *matA, *vecB, *vecC1,*vecC2;

                // Allocate memory
                matA = (double *) malloc(N*N * sizeof(double));
                vecB = (double *) malloc(N*N * sizeof(double));
                if(execNaive) vecC1 = (double *) malloc(N*N * sizeof(double));
                if(execOPT)   vecC2 = (double *) malloc(N*N * sizeof(double));

                // Initialize values
                randInitialize(N*N,matA);
                randInitialize(N,vecB);

                clock_t tic, toc;
                double tm;

                if(execNaive) {
                  // Perform naive matA x vecB = vecC1
                  tic = clock();
                  matVecMult(N,matA,vecB,vecC1);
                  toc = clock();
                  tm = (double)(toc - tic) / CLOCKS_PER_SEC;
                  printf("Elapsed time for naive mat-vec mult.: %f seconds\n",tm);
                }

                if(execOPT) {
                  // Perform optimized matA x vecB = vecC2
                  tic = clock();
                  matVecMult_opt(N,matA,vecB,vecC2);
                  toc = clock();
                  tm = (double)(toc - tic) / CLOCKS_PER_SEC;
                  printf("Elapsed time for optimized mat-vec mult.: %f seconds\n",tm);
                }

                // Verify results
                if(verif)
                    compareVecs(N,vecC2,vecC1);

                // Display results (don't use for large matrices)
                if(disp)
                {
                    displayMat(N,N,matA);
                    printf("\n");
                    displayVec(N,vecB);
                    printf("\n");
                    displayVec(N,vecC1);
                    printf("\n");
                }

                // Free memory
                free(matA);
                free(vecB);
                if(execNaive) free(vecC1);
                if(execOPT)   free(vecC2);
            }
            break;

        default:
            printf(" Invalid operation ID\n");
            return 0;
    }


    return 0;
}
void MainWindow::processImage() {
    // If this is the first time processing, initialize WB processing fields and return
    // without further processing
    if(!oldFrame.data) {
        oldRefinedBackground = Mat::zeros(currentFrame.size(), currentFrame.type());
        oldMarkerModel = Mat::zeros(currentFrame.size(), currentFrame.type());
        return;
    }

    // Get rectified versions of old and current frames
    Mat oldRectified = PAOLProcUtils::rectifyImage(oldFrame, corners);
    Mat currentRectified = PAOLProcUtils::rectifyImage(currentFrame, corners);

    //compare picture to previous picture and store differences in allDiffs
    float numDif;
    Mat allDiffs;
    PAOLProcUtils::findAllDiffsMini(allDiffs, numDif, oldRectified, currentRectified, 40, 1);

    // If there is a large enough difference, reset the stable whiteboard image count and do further processing
    if(numDif > .03) {
        // Reset stable whiteboard image count
        stableWhiteboardCount = 0;
        // Find true differences (ie. difference pixels with enough differences surrounding them)
        float refinedNumDif;
        Mat filteredDiffs;
        PAOLProcUtils::filterNoisyDiffs(filteredDiffs, refinedNumDif, allDiffs);
        displayMat(filteredDiffs, *ui->imDisplay4);

        // Find if there are enough true differences to update the current marker and whiteboard models
        // (ie. professor movement or lighting change detected)
        if(refinedNumDif > .04) {
            // Identify where the motion (ie. the professor) is
            Mat movement = PAOLProcUtils::expandDifferencesRegion(filteredDiffs);
            // Rescale movement info to full size
            Mat mvmtFullSize = PAOLProcUtils::enlarge(movement);
            displayMat(mvmtFullSize, *ui->imDisplay5);

            // Find marker candidates
            Mat markerCandidates = PAOLProcUtils::findMarkerStrokeCandidates(currentRectified);
            // Find marker locations
            Mat markerLocations = PAOLProcUtils::findMarkerStrokeLocations(currentRectified);
            // Keep marker candidates intersecting with marker locations
            Mat currentMarkerWithProf = PAOLProcUtils::filterConnectedComponents(markerCandidates, markerLocations);

            // Use the movement information to erase the professor
            Mat currentMarkerModel = PAOLProcUtils::updateModel(
                        oldMarkerModel, currentMarkerWithProf, mvmtFullSize);
            displayMat(currentMarkerModel, *ui->imDisplay6);

            // Find how much the current marker model differs from the stored one
            float markerDiffs = PAOLProcUtils::findMarkerModelDiffs(oldMarkerModel, currentMarkerModel);
            qDebug("numDif: %f", numDif);
            qDebug("refinedNumDif: %f", refinedNumDif);
            qDebug("markerDiffs: %f", markerDiffs);
            // Save and update the models if the marker content changed enough
            if(markerDiffs > .008) {
                // Save the smooth marker version of the old background image
                Mat oldRefinedBackgroundSmooth = PAOLProcUtils::smoothMarkerTransition(oldRefinedBackground);
                saveImageWithTimestamp(oldRefinedBackgroundSmooth);
                // Update marker model
                oldMarkerModel = currentMarkerModel.clone();
                // Update enhanced version of background
                Mat whiteWhiteboard = PAOLProcUtils::whitenWhiteboard(currentRectified, currentMarkerModel);
                oldRefinedBackground = PAOLProcUtils::updateModel(
                            oldRefinedBackground, whiteWhiteboard, mvmtFullSize);
                displayMat(oldRefinedBackground, *ui->imDisplay2);
            }
        }
    }
    // Otherwise, check if the frames are basically identical (ie. stable)
    else if(numDif < .000001) {
        stableWhiteboardCount++;
        // If the image has been stable for exactly twenty frames, the lecturer is not present, so we
        // can update the marker and whiteboard models without movement information
        if(stableWhiteboardCount == 20) {
            // Save the smooth marker version of the old background image
            Mat oldRefinedBackgroundSmooth = PAOLProcUtils::smoothMarkerTransition(oldRefinedBackground);
            saveImageWithTimestamp(oldRefinedBackgroundSmooth);

            // Update marker model
            // Find marker candidates
            Mat markerCandidates = PAOLProcUtils::findMarkerStrokeCandidates(currentRectified);
            // Find marker locations
            Mat markerLocations = PAOLProcUtils::findMarkerStrokeLocations(currentRectified);
            // Keep marker candidates intersecting with marker locations
            Mat currentMarkerModel = PAOLProcUtils::filterConnectedComponents(markerCandidates, markerLocations);

            oldMarkerModel = currentMarkerModel.clone();
            // Update enhanced version of background
            Mat whiteWhiteboard = PAOLProcUtils::whitenWhiteboard(currentRectified, currentMarkerModel);
            oldRefinedBackground = whiteWhiteboard.clone();
            displayMat(oldRefinedBackground, *ui->imDisplay2);
        }
    }
}
Example #10
0
void MainWindow::saveImageWithTimestamp(const Mat &frame) {
    // Don't actually save the image, just display what would have been saved
    displayMat(frame, *ui->imDisplay2);
}
void mixedLinearComplementarity_display(MixedLinearComplementarityProblem* p)
{
  int n = p->n;
  int m = p->m;
  printf("MLCP DISPLAY:\n-------------\n");
  printf("n :%d m: %d\n", p->n, p->m);


  printf(p->isStorageType1 ? "using (M)\n" : "not using (M)\n");
  printf(p->isStorageType2 ? "using (ABCD)\n" : "not using (ABCD)\n");
  if (p->blocksRows)
  {
    printf("blocks are:\n");
    int NumBlock = 0;
    while (p->blocksRows[NumBlock] < n + m)
    {
      if (p->blocksIsComp[NumBlock])
      {
        printf("->block of complementarity condition (type %d), from line %d, to line %d.\n", p->blocksIsComp[NumBlock], p->blocksRows[NumBlock], p->blocksRows[NumBlock + 1] - 1);
      }
      else
      {
        printf("->block of equality type (type %d), from line %d, to line %d.\n", p->blocksIsComp[NumBlock], p->blocksRows[NumBlock], p->blocksRows[NumBlock + 1] - 1);
      }
      NumBlock++;
    }
  }

  if (p->M)
  {
    printf("M matrix:\n");
    display(p->M);
  }
  else
    printf("No M matrix:\n");

  if (p->q)
  {
    printf("q matrix:\n");
    displayMat(p->q, n + m, 1, 0);
  }
  else
    printf("No q matrix:\n");

  if (p->A)
  {
    printf("A matrix:\n");
    displayMat(p->A, n, n, 0);
  }
  else
  {
    printf("No A matrix:\n");
    if (p->M && !p->M->storageType)
    {
      printf("A matrix from M:\n");
      displayMat(p->M->matrix0, n, n, n + m);
    }
  }
  if (p->B)
  {
    printf("B matrix:\n");
    displayMat(p->B, m, m, 0);
  }
  else
  {
    printf("No B matrix:\n");
    if (p->M && !p->M->storageType)
    {
      printf("B matrix from M:\n");
      displayMat(p->M->matrix0 + n * (n + m) + n, m, m, n + m);
    }
  }

  if (p->C)
  {
    printf("C matrix:\n");
    displayMat(p->C, n, m, 0);
  }
  else
  {
    printf("No C matrix:\n");
    if (p->M && !p->M->storageType)
    {
      printf("C matrix from M:\n");
      displayMat(p->M->matrix0 + n * (n + m), n, m, n + m);
    }
  }

  if (p->D)
  {
    printf("D matrix:\n");
    displayMat(p->D, m, n, 0);
  }
  else
  {
    printf("No D matrix:\n");
    if (p->M && !p->M->storageType)
    {
      printf("D matrix from M:\n");
      displayMat(p->M->matrix0 + n, m, n, n + m);
    }
  }
  if (p->a)
  {
    printf("a matrix:\n");
    displayMat(p->a, n, 1, 0);
  }
  else
    printf("No a matrix:\n");
  if (p->b)
  {
    printf("b matrix:\n");
    displayMat(p->b, m, 1, 0);
  }
  else
    printf("No b matrix:\n");

}