Ejemplo n.º 1
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    connect(ui->openButton, SIGNAL(clicked()), this, SLOT(Open()));
    connect(ui->saveButton, SIGNAL(clicked()), this, SLOT(SaveImage()));
    connect(ui->SSDButton, SIGNAL(clicked()), this, SLOT(SSD()));
    connect(ui->SADButton, SIGNAL(clicked()), this, SLOT(SAD()));
    connect(ui->NCCButton, SIGNAL(clicked()), this, SLOT(NCC()));
    connect(ui->GTCheckBox, SIGNAL(clicked()), this, SLOT(GTOnOff()));
    connect(ui->gaussianButton, SIGNAL(clicked()), this, SLOT(Gaussian()));
    connect(ui->maxButton, SIGNAL(clicked()), this, SLOT(FindBestDisparity()));
    connect(ui->bilateralButton, SIGNAL(clicked()), this, SLOT(Bilateral()));
    connect(ui->segmentButton, SIGNAL(clicked()), this, SLOT(Segment()));
    connect(ui->renderButton, SIGNAL(clicked()), this, SLOT(Render()));
    connect(ui->renderSlider, SIGNAL(valueChanged(int)), this, SLOT(RenderSlider(int)));
    connect(ui->magicButton, SIGNAL(clicked()), this, SLOT(MagicStereo(int)));

    ui->GTCheckBox->setChecked(true);
    ui->pixelErrorLabel->setText("");
    ui->gaussianSigmaSpinBox->setValue(1.0);
    ui->biSigmaSSpinBox->setValue(1.0);
    ui->biSigmaISpinBox->setValue(20.0);
    ui->renderSlider->setValue(100);
    ui->SADOffsetBox->setValue(2);
    ui->SSDOffsetBox->setValue(2);
    ui->NCCOffsetBox->setValue(2);
    ui->segmentGridBox->setValue(20);
    ui->segmentColorSpinBox->setValue(20.0);
    ui->segmentSpatialSpinBox->setValue(6.0);
    ui->segmentIterBox->setValue(4);

    m_Image1Display.setParent(ui->tab);
    m_Image2Display.setParent(ui->tab_2);
    m_GTDisplay.setParent(ui->tab_4);
    m_DisparityDisplay.setParent(ui->tab_3);
    m_ErrorDisplay.setParent(ui->tab_5);
    m_RenderDisplay.setParent(ui->tab_6);
    m_SegmentDisplay.setParent(ui->tab_7);

    m_Image1Display.window = this;
    m_Image2Display.window = this;
    m_GTDisplay.window = this;
    m_DisparityDisplay.window = this;
    m_ErrorDisplay.window = this;
    m_RenderDisplay.window = this;
    m_SegmentDisplay.window = this;

    ui->tabWidget->setCurrentIndex(0);

    m_LastRow = 0;
    m_SegmentIteration = 0;
    m_MatchCost = NULL;



}
Ejemplo n.º 2
0
uint64_t x264_pixel_ssd_wxh( x264_pixel_function_t *pf, pixel *pix1, intptr_t i_pix1,
                             pixel *pix2, intptr_t i_pix2, int i_width, int i_height )
{
    uint64_t i_ssd = 0;
    int y;
    int align = !(((intptr_t)pix1 | (intptr_t)pix2 | i_pix1 | i_pix2) & 15);

#define SSD(size) i_ssd += pf->ssd[size]( pix1 + y*i_pix1 + x, i_pix1, \
                                          pix2 + y*i_pix2 + x, i_pix2 );
    for( y = 0; y < i_height-15; y += 16 )
    {
        int x = 0;
        if( align )
            for( ; x < i_width-15; x += 16 )
                SSD(PIXEL_16x16);
        for( ; x < i_width-7; x += 8 )
            SSD(PIXEL_8x16);
    }
    if( y < i_height-7 )
        for( int x = 0; x < i_width-7; x += 8 )
            SSD(PIXEL_8x8);
#undef SSD

#define SSD1 { int d = pix1[y*i_pix1+x] - pix2[y*i_pix2+x]; i_ssd += d*d; }
    if( i_width & 7 )
    {
        for( y = 0; y < (i_height & ~7); y++ )
            for( int x = i_width & ~7; x < i_width; x++ )
                SSD1;
    }
    if( i_height & 7 )
    {
        for( y = i_height & ~7; y < i_height; y++ )
            for( int x = 0; x < i_width; x++ )
                SSD1;
    }
#undef SSD1

    return i_ssd;
}
Ejemplo n.º 3
0
int64_t x264_pixel_ssd_wxh( x264_pixel_function_t *pf, uint8_t *pix1, int i_pix1, uint8_t *pix2, int i_pix2, int i_width, int i_height )
{
    int64_t i_ssd = 0;
    int x, y;

#define SSD(size) i_ssd += pf->ssd[size]( pix1 + y*i_pix1 + x, i_pix1, \
                                          pix2 + y*i_pix2 + x, i_pix2 );
    for( y = 0; y < i_height-15; y += 16 )
    {
        for( x = 0; x < i_width-15; x += 16 )
            SSD(PIXEL_16x16);
        if( x < i_width-7 )
            SSD(PIXEL_8x16);
    }
    if( y < i_height-7 )
        for( x = 0; x < i_width-7; x += 8 )
            SSD(PIXEL_8x8);
#undef SSD

#define SSD1 { int d = pix1[y*i_pix1+x] - pix2[y*i_pix2+x]; i_ssd += d*d; }
    if( i_width % 8 != 0 )
    {
        for( y = 0; y < (i_height & ~7); y++ )
            for( x = i_width & ~7; x < i_width; x++ )
                SSD1;
    }
    if( i_height % 8 != 0 )
    {
        for( y = i_height & ~7; y < i_height; y++ )
            for( x = 0; x < i_width; x++ )
                SSD1;
    }
#undef SSD1

    return i_ssd;
}
Ejemplo n.º 4
0
			static ::libmaus2::autoarray::AutoArray < ::libmaus2::graph::TripleEdge > decompatDecompacterSingle(
				stream_type & stream,
				uint64_t const numtotaledges,
				uint64_t const srcbase
				)
			{
				SingleStreamDecompacter<stream_type> SSD(stream,srcbase);

				::libmaus2::autoarray::AutoArray< ::libmaus2::graph::TripleEdge > edges(numtotaledges,false);
				for ( uint64_t i = 0; i < numtotaledges; ++i )
				{
					bool const ok = SSD.getNext(edges[i]);
					assert ( ok );
				}

				return edges;
			}
double TransformErrFunction::getErr(const Transform * T1, const Transform * T2, int inlierCount)
{
    double projErr = 0;
    for(TPointVec::iterator pPoint = pointVec_.begin(); pPoint != pointVec_.end(); pPoint++)
    {
        CvPoint2D64f point = *pPoint;
        CvPoint2D64f transformedPoint1 = T1->applyToPoint(point);
        CvPoint2D64f transformedPoint2 = T2->applyToPoint(point);
        projErr += SSD(transformedPoint1, transformedPoint2);
    }

    if(eWeightByInlierCountSquared_ == eWeightByInlierCount)
    {
        projErr *= (double)(inlierCount);
    }
    else if(eWeightByInlierCountSquared_ == eWeightByInlierCountSquared)
    {
        projErr *= (double)(inlierCount*inlierCount);
    }

    return projErr;
}
Ejemplo n.º 6
0
int main()
{
    //initiation
	const char* imgname[4]={"Tsukuba","Venus","Teddy","Cones"};
	int MAX_Disp[4]={16,20,60,60};
	int scale[4]={16,8,4,4};	
	char imL[30],imR[30],imDisp[30],truedisp[30],non_occ[30];
	IplImage *pImgl,*pImgr,*pDisp,*pTruedisp,*pNon_occ;
	int w,h,step;	//width,height,widthStep
	unsigned char *left,*right,*disp,*groundtruth,*nonocc;
	float time,err_nonocc;

	for(int i=0;i<4;i++)
	{
		sprintf(imL,"img/%s/imL.png",imgname[i]);
		sprintf(imR,"img/%s/imR.png",imgname[i]);
		sprintf(truedisp,"img/%s/groundtruth.png",imgname[i]);
		sprintf(non_occ,"img/%s/nonocc.png",imgname[i]);
		printf("loading %s\n",imgname[i]);
		pImgl = cvLoadImage(imL,0);
		if(pImgl == NULL) printf("cannot open imgl!\n");
    	pImgr = cvLoadImage(imR,0);
	    if(pImgr == NULL) printf("cannot open imgr!\n");
    	pTruedisp = cvLoadImage(truedisp,0);
	    if(pTruedisp == NULL) printf("cannot open truedisp!\n");
    	pNon_occ = cvLoadImage(non_occ,0);
	    if(pNon_occ == NULL) printf("cannot open non_occ!\n");
		pDisp = cvCreateImage(cvGetSize(pImgl),pImgl->depth,pImgl->nChannels);

		w=pImgl->width;
		h=pImgl->height;
		step=pImgl->widthStep;
		left  = new unsigned char[w*h];
		right = new unsigned char[w*h];
		disp  = new unsigned char[w*h];
		groundtruth  = new unsigned char[w*h];
		nonocc  = new unsigned char[w*h];
	
		for(int y=0;y<h;y++)
			for(int x=0;x<w;x++)
			{
				left[y*w+x] =(unsigned char) pImgl->imageData[y*step+x];	
				right[y*w+x] =(unsigned char) pImgr->imageData[y*step+x];
				groundtruth[y*w+x] =(unsigned char) pTruedisp->imageData[y*step+x];
				nonocc[y*w+x] =(unsigned char) pNon_occ->imageData[y*step+x];
			}	

		//SAD
		time=SAD(left,right,disp,w,h,MAX_Disp[i],scale[i]);
		err_nonocc = eval_nonocc(groundtruth,disp,nonocc,w,h,scale[i]);	
		for(int y=0;y<h;y++)
            for(int x=0;x<w;x++)
				pDisp->imageData[y*step+x] = (char)disp[y*w+x];
		sprintf(imDisp,"img/%s/disp_SAD.png",imgname[i]);
	    cvSaveImage(imDisp,pDisp);
		printf("SAD algorithm\n");
		printf("proccessing time:\t%6.3fms\n",time);
		printf("Percentage of Bad Matching pixels:\t%6.3f%%\n",err_nonocc*100);
	
		//SSD
		time=SSD(left,right,disp,w,h,MAX_Disp[i],scale[i]);
		err_nonocc = eval_nonocc(groundtruth,disp,nonocc,w,h,scale[i]);	
		for(int y=0;y<h;y++)
            for(int x=0;x<w;x++)
				pDisp->imageData[y*step+x] = (char)disp[y*w+x];
		sprintf(imDisp,"img/%s/disp_SSD.png",imgname[i]);
	    cvSaveImage(imDisp,pDisp);
		printf("SSD algorithm\n");
		printf("proccessing time:\t%6.3fms\n",time);
		printf("Percentage of Bad Matching pixels:\t%6.3f%%\n",err_nonocc*100);
	
		//cudaSSD
		time = cudaSSD(left,right,disp,w,h,MAX_Disp[i],scale[i]);
		err_nonocc = eval_nonocc(groundtruth,disp,nonocc,w,h,scale[i]);	
		for(int y=0;y<h;y++)
            for(int x=0;x<w;x++)
				pDisp->imageData[y*step+x] = (char)disp[y*w+x];
		sprintf(imDisp,"img/%s/disp_cudaSSD.png",imgname[i]);
	    cvSaveImage(imDisp,pDisp);
		printf("cudaSSD algorithm\n");
		printf("proccessing time:\t%6.3fms\n",time);
		printf("Percentage of Bad Matching pixels:\t%6.3f%%\n",err_nonocc*100);

/*		//cudaSAD
		time = cudaSAD(left,right,disp,w,h,MAX_Disp[i],scale[i]);
		err_nonocc = eval_nonocc(groundtruth,disp,nonocc,w,h,scale[i]);	
		for(int y=0;y<h;y++)
            for(int x=0;x<w;x++)
				pDisp->imageData[y*step+x] = (char)disp[y*w+x];
		sprintf(imDisp,"img/%s/disp_cudaSAD.png",imgname[i]);
	    cvSaveImage(imDisp,pDisp);
		printf("cudaSAD algorithm\n");
		printf("proccessing time:\t%6.3fms\n",time);
		printf("Percentage of Bad Matching pixels:\t%6.3f%%\n",err_nonocc*100);
*/
		printf("\n");

		delete []left;
		delete []right;
		delete []disp;
	}

    return 0;
}
Ejemplo n.º 7
0
void SelfSimDescriptor::compute(const Mat& img, vector<float>& descriptors, Size winStride,
                                const vector<Point>& locations) const
{
    CV_Assert( img.depth() == CV_8U );

    winStride.width = std::max(winStride.width, 1);
    winStride.height = std::max(winStride.height, 1);
    Size gridSize = getGridSize(img.size(), winStride);
    int i, nwindows = locations.empty() ? gridSize.width*gridSize.height : (int)locations.size();
    int border = largeSize/2 + smallSize/2;
    int fsize = (int)getDescriptorSize();
    vector<float> tempFeature(fsize+1);
    descriptors.resize(fsize*nwindows + 1);
    Mat ssd(largeSize, largeSize, CV_32F), mappingMask;
    computeLogPolarMapping(mappingMask);

#if 0 //def _OPENMP
    int nthreads = cvGetNumThreads();
    #pragma omp parallel for num_threads(nthreads)
#endif
    for( i = 0; i < nwindows; i++ )
    {
        Point pt;
        float* feature0 = &descriptors[fsize*i];
        float* feature = &tempFeature[0];
        int x, y, j;

        if( !locations.empty() )
        {
            pt = locations[i];
            if( pt.x < border || pt.x >= img.cols - border ||
                pt.y < border || pt.y >= img.rows - border )
            {
                for( j = 0; j < fsize; j++ )
                    feature0[j] = 0.f;
                continue;
            }
        }
        else
            pt = Point((i % gridSize.width)*winStride.width + border,
                       (i / gridSize.width)*winStride.height + border);

        SSD(img, pt, ssd);

        // Determine in the local neighborhood the largest difference and use for normalization
        float var_noise = 1000.f;
        for( y = -1; y <= 1 ; y++ )
            for( x = -1 ; x <= 1 ; x++ )
                var_noise = std::max(var_noise, ssd.at<float>(largeSize/2+y, largeSize/2+x));

        for( j = 0; j <= fsize; j++ )
            feature[j] = FLT_MAX;

        // Derive feature vector before exp(-x) computation
        // Idea: for all  x,a >= 0, a=const.   we have:
        //       max [ exp( -x / a) ] = exp ( -min(x) / a )
        // Thus, determine min(ssd) and store in feature[...]
        for( y = 0; y < ssd.rows; y++ )
        {
            const schar *mappingMaskPtr = mappingMask.ptr<schar>(y);
            const float *ssdPtr = ssd.ptr<float>(y);
            for( x = 0 ; x < ssd.cols; x++ )
            {
                int index = mappingMaskPtr[x];
                feature[index] = std::min(feature[index], ssdPtr[x]);
            }
        }

        var_noise = -1.f/var_noise;
        for( j = 0; j < fsize; j++ )
            feature0[j] = feature[j]*var_noise;
        Mat _f(1, fsize, CV_32F, feature0);
        cv::exp(_f, _f);
    }
}