示例#1
0
void Crossline::Process(const cv::Mat& prevImg, const cv::Mat& nextImg, float** density_feature, float** x_feature, float** y_feature) {
  std::vector<cv::Mat> src1_spl;
  std::vector<cv::Mat> src2_spl;

  split(prevImg, src1_spl);
  split(nextImg, src2_spl);

  std::vector<cv::Mat> channels;
  channels.push_back(src1_spl[0]);
  channels.push_back(src1_spl[1]);
  channels.push_back(src1_spl[2]);
  channels.push_back(src2_spl[0]);
  channels.push_back(src2_spl[1]);
  channels.push_back(src2_spl[2]);
  cv::Mat input_data;
  merge(channels, input_data);

  std::vector<cv::Mat> dv (1, input_data);
  std::vector<int> dv1 (1, 0);

  md_layer_->AddMatVector(dv, dv1);

  feature_extraction_net_->ForwardFromTo(0, feature_extraction_net_->layers().size() - 1);
  const shared_ptr<Blob<float> > feature_blob_density = feature_extraction_net_->blob_by_name("density_out");
  const shared_ptr<Blob<float> > feature_blob_X = feature_extraction_net_->blob_by_name("vx_out");
  const shared_ptr<Blob<float> > feature_blob_Y = feature_extraction_net_->blob_by_name("vy_out");

  *density_feature = feature_blob_density->mutable_cpu_data();
  *x_feature = feature_blob_X->mutable_cpu_data();
  *y_feature = feature_blob_Y->mutable_cpu_data();
}
示例#2
0
float* Reid::CalcFeatures(const std::vector<cv::Mat>& images,
    const std::string& feature_blob_name) const {
  // initialize dummy labels, which is required by MemoryDataLayer
  std::vector<int> dv1(images.size(), 0);
  // Note: for sake of efficiency,
  // we don't check the input image size, which
  // should be cv::Size(56, 144) exactly, or the program will crash
  md_layer_->AddMatVector(images, dv1);
  // forward
  feature_extraction_net_->ForwardFromTo(
    0, feature_extraction_net_->layers().size() - 1);
  // extract feature blob
  return feature_extraction_net_->blob_by_name(
    feature_blob_name)->mutable_cpu_data();
}
示例#3
0
int main()
{
	double ar[SIZE_ar] = { 0, 1, 2, 3, 4, 5 };
	double ar2[SIZE_ar2] = { 8,7,6,5,4,3,2,1,0};

	DoubleVector dv1(SIZE_ar, ar);
	DoubleVector dv2(SIZE_ar2, ar2);

	DoubleVector dv3;
	dv3 = dv1;

	double p = dv1[1];

	DoubleVector v;
	v =  dv2 + dv1 + dv1 - dv2 - dv1;
	v.print();

	dv1 += dv3 += dv2 -= dv2;
	dv1.print();

	dv1 = dv3 * 2 * 4 ;
	dv1 *= 2;
	dv3 = dv1 / 2;
	dv3 /= 2;
	double scalar = dv3% dv1;

	BoolVector a(2);
	cout<<"number in binary ...00000010 --> in array pos[31] bit is "<<a[31]
		<<endl<<"in array pos[3] - bit is "<<a[30]<<endl;
	a.set(30);
	cout << "Nothing changes because in pos 30 it has 1. The number is the same (2) :" << a.get_number()<<endl;
	a.set(31);
	cout << "Change on pos 31 from 0 to 1. The new number is 3:" << a.get_number()<<endl;
	
	BoolVector b(55);
	b.set(28);
	cout << "We are working with this number 00..110111 in binary (decimal 55)."<<endl
		<<"We want to make it 00.. 111111 exacly 63 in decimal : " << b.get_number() << endl;
	b.get(28);
	cout << "We are working with 00.. 111111 decimal 63 changing into  00..110111  decimal 55:" << b.get_number() << endl;
}
示例#4
0
void resultCombiner(const char * name_dv1, const char * name_cm1, const int length1, const char * name_dv2, const char * name_cm2, const int length2, int ftr = 1, const char * outputNameStub = "output")
{
    TVectorD dv1(length1), dv2(length2);
    TMatrixT<double> cm1(length1, length1), cm2(length2, length2);
    double binLimits1[length1][2], binLimits2[length2][2], ccCov1[length1], ccCov2[length1];

    readDataVector(name_dv1, dv1, binLimits1, ftr, ccCov1);
    printf("Read data vector 1 (%d)\n",length1);

    readDataVector(name_dv2, dv2, binLimits2, ftr, ccCov2);
    printf("Read data vector 2 (%d)\n",length2);

    readCovMatrix(name_cm1, cm1);
    printf("Read covariance matrix 1\n");

    readCovMatrix(name_cm2, cm2);
    printf("Read covariance matrix 2\n");

    std::vector<double*> binLimits;
    std::vector<std::vector<int > > preU;
    int i1 = 0, i2 = 0;
    while(i1 < length1 || i2 < length2)
    {
        if(i1 < length1 && i2 < length2)
        {
            if((binLimits1[i1][1] + binLimits1[i1][0])/2 > binLimits2[i2][0] && (binLimits1[i1][1] + binLimits1[i1][0])/2 < binLimits2[i2][1])
            {
                binLimits.push_back(binLimits1[i1]);
                std::vector<int> tmp;
                tmp.push_back(i1);
                tmp.push_back(i2);
                preU.push_back(tmp);
                i1++;
                i2++;
            }
            else if((binLimits1[i1][1] + binLimits1[i1][0])/2 <= binLimits2[i2][0])
            {
                binLimits.push_back(binLimits1[i1]);
                std::vector<int> tmp;
                tmp.push_back(i1);
                tmp.push_back(-1);
                preU.push_back(tmp);
                i1++;
            }
            else
            {
                binLimits.push_back(binLimits2[i2]);
                std::vector<int> tmp;
                tmp.push_back(-1);
                tmp.push_back(i2);
                preU.push_back(tmp);
                i2++;
            }
        }
        else if(i1 < length1 && i2 >= length2)
        {
            binLimits.push_back(binLimits1[i1]);
            std::vector<int> tmp;
            tmp.push_back(i1);
            tmp.push_back(-1);
            preU.push_back(tmp);
            i1++;
        }
        else
        {
            binLimits.push_back(binLimits2[i2]);
            std::vector<int> tmp;
            tmp.push_back(-1);
            tmp.push_back(i2);
            preU.push_back(tmp);
            i2++;
        }
    }

    TVectorD dv(length1 + length2);
    for(int i = 0; i < length1 + length2; i++)
    {
        dv[i] = (i < length1) ? dv1[i] : dv2[i - length1];
    }

    TMatrixT<double> cm(length1 + length2, length1 + length2), U(length1 + length2, preU.size());
    for(int i = 0; i < length1; i++)
    {
        for(int j = 0; j < length1; j++)
        {
            cm[i][j] = cm1[i][j];
        }
    }
    for(int i = length1; i < length1 + length2; i++)
    {
        for(int j = length1; j < length1 + length2; j++)
        {
            cm[i][j] = cm2[i - length1][j - length1];
        }
    }

    for(unsigned int i = 0; i < preU.size(); i++)
    {
        if(preU[i][0] >= 0) U[preU[i][0]][i] = 1;
        if(preU[i][1] >= 0) U[preU[i][1] + length1][i] = 1;
        if(ftr > 1 && preU[i][0] >= 0 && preU[i][1] >= 0)  cm[preU[i][0]][preU[i][1] + length1] = cm[preU[i][1] + length1][preU[i][0]] = ccCov1[preU[i][0]]*ccCov2[preU[i][1]];
    }
    
    //    cm.Print();

    TMatrixT<double> Ut(U);
    Ut.T();

    TMatrixT<double> cmInv(cm);
    cmInv.Invert();
    TMatrixT<double> step1 = Ut * cmInv * U;
    TMatrixT<double> step2 = Ut * cmInv;
    TMatrixT<double> lambda = step1.Invert() * step2;
    TVectorD bV = lambda*dv;
    TMatrixT<double> bcm = (Ut * cmInv * U).Invert();

    printf("Done with combination.\n");

    //write output
    FILE *file;
    char bVoutName[128], CMoutName[128];
    sprintf(bVoutName, "%s_data.txt", outputNameStub);

    file = fopen(bVoutName, "w");
    if(file)
    {
        fprintf(file, "#\n#%9s %9s %9s %15s %15s\n", "Bin", "Y_min", "Y_max", "Value", "Uncertainty");
        for(int i = 0; i < bV.GetNoElements(); i++)
        {
            fprintf(file, " %9i %9.2f %9.2f %15e %15e\n", i + 1, binLimits[i][0], binLimits[i][1], bV[i], sqrt(bcm[i][i]));
        }
        fclose(file);
    }

    sprintf(CMoutName, "%s_covMat.txt", outputNameStub);

    file = fopen(CMoutName, "w");
    if(file)
    {
        fprintf(file, "#\n#%9s %9s %15s\n", "Bin i", "Bin j", "Value");
        for(int i = 0; i < bcm.GetNrows(); i++)
        {
            for(int j = 0; j < bcm.GetNcols(); j++)
            {
                fprintf(file, " %9i %9i %15e\n", i + 1, j + 1, bcm[i][j]);
            }
        }
        fclose(file);
    }
    printf("Output complete.\n");
}