Пример #1
0
void ImageViewer::suppression(QImage &img,  std::vector<double> &vect)
{
	double max = vect[0];
	int max_index = 0;

	findMaximum(vect, &max, &max_index);
	while (max != 0) {
		detectedPedestrian(max_index, img);
		vect[max_index] = 0;
		nullInArea(vect, max_index);
		max = vect[0];
		max_index = 0;
		findMaximum(vect, &max, &max_index);
	}
}
Пример #2
0
int main() {

  findMaximum();

  return EXIT_SUCCESS;

}
Пример #3
0
TProfile* rescaleProfile(TProfile *p)
{
  TFitResultPtr fit=p->Fit("pol4","R+","",-9,9);
  float max=findMaximum(p->GetFunction("pol4"),4);
  TProfile* p1=(TProfile*)p->Clone(p->GetName()+TString("_rescaled"));
  p1->Scale(1./max);
  p1->GetYaxis()->SetTitle("Normalized response [a.u.]");
  return p1;
}
void ConjProjection(double *result, double *a, double *weights)
{
    double g[MAXK];
    double yInit[MAXK];
    double y[MAXK];
    int activeSet[MAXK];
    double sumW;
    double sumA;
    double sumL;
    int j;
    int negCount;
    double sumGINACT, sumGACTY;
    int iterations;
    double lambda[MAXK];
    double ggM; int ggExcl;
    double sumAbsX;
    
    /* Check if vector has too large variates */
    findMaximum(&ggM, &ggExcl, a);
    for(sumAbsX = 0,j = 0; j < K; j++)
        sumAbsX += fabs(a[j]);
    if(ggM > 0 && sumAbsX - ggM < 1e-5) {
        for(j = 0; j < K; j++)
            result[j] = 0;
        result[ggExcl] = 1;
        return;
    }

    for(sumW = 0, sumA = 0, j = 0; j < K; j++) {
        sumW += 1/weights[j];
        sumA += a[j];
    }
    for(j = 0; j < K; j++) 
        g[j] = -1/(sumW*weights[j]);
    //Initial projection to weights'y = 1.
    for(j = 0; j < K; j++) {
        y[j] = a[j] - g[j] + g[j]*sumA;
        yInit[j] = y[j];
    }
    // activeSet = zeros(K, 1);
    for(j = 0; j < K; j++)
        activeSet[j] = 0;
    //////////////
    // main loop
    //////////////
    for(iterations = 0; iterations < K; j++) {
        for(negCount = 0,j = 0; j < K; j++)
            if(y[j] < 0) {
                negCount++;
                activeSet[j] = 1;
            }
        if(negCount == 0) {
            for(j = 0; j < K; j++) 
                result[j] = y[j];
            return;
        }
        for(sumGACTY = 0, sumGINACT = 0, j = 0; j < K; j++) {
            if(activeSet[j] == 1)
                sumGACTY += g[j]*yInit[j];
            else
                sumGINACT += g[j];
            lambda[j] = 0;
        }
        // Iterate between recalculating Lagrange operators & proj to sum(y) = 1
        for(sumL = 0, j = 0; j < K; j++) {
            if(activeSet[j] == 0)
                lambda[j] = 0;
            else
                lambda[j] = -yInit[j] - sumGACTY / sumGINACT;
            sumL += lambda[j];
        }
        for(j = 0; j < K; j++) {
            if(activeSet[j] == 0)
                y[j] = a[j] - g[j] + g[j]*sumA + g[j]*sumL + lambda[j];
            else
                y[j] = 0;
        }
    }
    printf("conjugateProjection: Algorithm failed after K = %f iterations!\n", K);
}
Пример #5
0
int findHeight(treeNode *node) {
	if (node == NULL) {
		return -1;
	}
	return findMaximum(findHeight(node->left), findHeight(node->right)) + 1;
}
Пример #6
0
    int main(int argc, char **argv) {


        if (argc != 4) {
            exit_with_help();
        }

        LOGD( "start to get feature of audio file" );

        FILE *soundfile = NULL;
        FILE *chirpfile = NULL;
        FILE *featurefile = NULL;
        char *sound_filename = NULL;
        char *chirp_filename = NULL;
        char *feature_filename = NULL;
        sound_filename = argv[1];
        chirp_filename = argv[2];
        feature_filename = argv[3];

        int numSample = 0;
        int rawaudioSignals[200000];
        int value;


        int i2 = 0;
        float chirp[301];
        float chirp_value;

        if (sound_filename) {
            soundfile = fopen(sound_filename, "r");
            if (soundfile == NULL) {
                fprintf(stderr, "can't open file %s\n", sound_filename);
                exit(1);
            }
        }

        while (fscanf(soundfile, "%d", &value) > 0) {
            rawaudioSignals[numSample] = value;
            numSample++;
            if (numSample == 199998) {
                break;
            }
        }

        if (chirp_filename) {
            chirpfile = fopen(chirp_filename, "r");
            if (chirpfile == NULL) {
                fprintf(stderr, "can't open file %s\n", chirp_filename);
                exit(1);
            }
        }

        while (fscanf(chirpfile, "%f", &chirp_value) > 0) {
            chirp[i2] = chirp_value;
            i2++;
        }


        double *audio_signal = (double *) malloc(numSample * sizeof(double));
        if (audio_signal == NULL) {
            /* we have a problem */
            fprintf(stderr, "Error: out of memory.\n");
            return 1;
        }


        for (int j = 0; j < numSample; j++) {
            audio_signal[j] = (double) rawaudioSignals[j];
        }

        double *match_signal = (double *) malloc(numSample * sizeof(double));
        if (match_signal == NULL) {
            /* we have a problem */
            fprintf(stderr, "Error: out of memory.\n");
            return 1;
        }


        Dsp::SimpleFilter<Dsp::Butterworth::BandPass<5>, 1> f;
        f.setup(5,    // order
                48000,// sample rate
                15000, // center frequency
                3000);  // band width);
        f.process(numSample, &audio_signal);

//    FILE *outf_filter = fopen("filter1_0403_test2.txt", "w");
//
//    for ( int j=0; j<numSample; j++ )
//    {
//        //printf("%f\n", audio_signal[j]);
//        fprintf(outf_filter, "%f  ", audio_signal[j]);
//    }



        convCalculate(chirp, audio_signal, match_signal, numSample);

        FILE *outf_conv = fopen("convert1_0403_22_sound11.txt", "w");

//        for (int j = 0; j < numSample; j++) {
//            //printf("%f\n", audio_signal[j]);
//            fprintf(outf_conv, "%f  ", match_signal[j]);
//        }


//        printf("%d\n", numSample);

//    FILE *outf = fopen("results1_0307_test2.txt", "w");
//
//    for ( int j=0; j<numSample; j++ )
//    {
//        //printf("%f\n", audio_signal[j]);
//        fprintf(outf, "%f  ", audio_signal[j]);
//    }

        int duration1 = 2300;
        int duration2 = 2000;
        int f_start = 600;
        int f_end = 1500;
        int focus_duration = 900;
        int step = 100;
        int peak_threshold = 200;
        int threshold = 200000;
        int threshold2 = 2000000;

        double tmp_whole_max = 0;
        int tmp_whole_max_index = 0;

        double tmp_echo_max = 0;
        int tmp_echo_max_index = 0;

        double tmp_max = 0;
        int tmp_max_index = 0;

        double tmp_exceed_threshold = 0;
        int tmp_exceed_index = 0;

        int focus_start_list[10];
        int focus_end_list[10];
        int focus_count = 0;

        int whole_start = 0;


        tmp_whole_max_index = findMaximum(&match_signal[0], whole_start, numSample, tmp_whole_max);
//    printf("%d\n", tmp_whole_max_index);
//    printf("%f\n", tmp_whole_max);

        while (tmp_whole_max > threshold) {

            tmp_exceed_index = ExceedThreshold(&match_signal[0], whole_start, numSample, threshold,
                                               tmp_exceed_threshold);
//            printf("process raw sound file  %s\n", sound_filename);
//            printf("tmp_exceed_index  %d\n", tmp_exceed_index);
//            printf("tmp_whole_max  %f\n", tmp_whole_max);

            int tmp_start = tmp_exceed_index;
            int tmp_end = tmp_exceed_index + duration1;
            whole_start = tmp_end;
//            printf("whole_start  %d\n", whole_start);
            if ((tmp_start < 0) | (tmp_end > numSample)) {

                break;
            }
            tmp_max_index = findMaximum(&match_signal[0], tmp_start, tmp_end, tmp_max);
//            printf("tmp_max_index  %d\n", tmp_max_index);
//            printf("tmp_max  %f\n", tmp_max);


            int tmp_end2 = tmp_max_index + duration2;

            tmp_echo_max_index = findMaximum(&match_signal[0], (tmp_max_index + f_start), (tmp_max_index + f_end),
                                             tmp_echo_max);

            if ((tmp_end2 > tmp_end) || (tmp_echo_max > threshold2)) {
                tmp_whole_max_index = findMaximum(&match_signal[0], whole_start, numSample, tmp_whole_max);
                continue;
            }
            focus_start_list[focus_count] = tmp_max_index + f_start;
            focus_end_list[focus_count] = tmp_max_index + f_end;
            focus_count = focus_count + 1;


            tmp_whole_max_index = findMaximum(&match_signal[0], whole_start, numSample, tmp_whole_max);

        }

//        for (int i = 0; i < focus_count; i++) {
//            printf("%d\t", focus_start_list[i]);
//            printf("%d\n", focus_end_list[i]);
//
//        }

        double *ave_focus = (double *) malloc(focus_duration * sizeof(double));
        if (ave_focus == NULL) {
            /* we have a problem */
            printf("Error: out of memory.\n");
            return 1;
        }

        average(&match_signal[0], &focus_start_list[0], focus_count, focus_duration, &ave_focus[0]);

        double Energy = getEnergy(&ave_focus[0], focus_duration);

        int numPeaks = 0;
        numPeaks = findPeaks(&ave_focus[0], focus_duration, peak_threshold);
//        printf("\n\n%d\n", numPeaks);

        double mean_var = 0.0;
        double max_var = 0.0;

        getVarResult(&ave_focus[0], focus_duration, step, mean_var, max_var);
//        printf("%f\n", mean_var);
//        printf("%f\n", max_var);


        if (feature_filename) {
            featurefile = fopen(feature_filename, "w");
            if (featurefile == NULL) {
                fprintf(stderr, "can't open file %s\n", feature_filename);
                exit(1);
            }
        }


        fprintf(featurefile, "0 ");
        fprintf(featurefile, "1:%f ", Energy);
        fprintf(featurefile, "2:%d ", numPeaks);
        fprintf(featurefile, "3:%f ", mean_var);
        fprintf(featurefile, "4:%f\n", max_var);


//        printf("finish raw sound file  %s\n", sound_filename);

        free(audio_signal);
        free(match_signal);
        free(ave_focus);
//    fclose(outf);
//    fclose(outf_conv);
        fclose(soundfile);
        fclose(chirpfile);
        fclose(featurefile);

        return 0;


    }