예제 #1
0
파일: utils.cpp 프로젝트: chutsu/slam
void cvmatconcat(cv::Mat img1, cv::Mat img2, cv::Mat &out)
{
    cv::Size size1;
    cv::Size size2;

    // setup
    size1 = img1.size();
    size2 = img2.size();
    out = cv::Mat(
        size1.height,
        size1.width + size2.width,
        img1.type()
    );

    // copy image 1 to the left
    out.adjustROI(0, 0, 0, -size2.width);
    img1.copyTo(out);

    // copy image 2 to the right
    out.adjustROI(0, 0, -size1.width, size2.width);
    img2.copyTo(out);

    // restore original roi
    out.adjustROI(0, 0, size1.width, 0);
}
예제 #2
0
void cv::ocl::oclMat::download(cv::Mat &m) const
{
    CV_DbgAssert(!this->empty());
    m.create(wholerows, wholecols, type());

    if(m.channels() == 3)
    {
        int pitch = wholecols * 3 * m.elemSize1();
        int tail_padding = m.elemSize1() * 3072;
        int err;
        cl_mem temp = clCreateBuffer(*(cl_context*)clCxt->getOpenCLContextPtr(), CL_MEM_READ_WRITE,
                                     (pitch * wholerows + tail_padding - 1) / tail_padding * tail_padding, 0, &err);
        openCLVerifyCall(err);

        convert_C4C3(*this, temp);
        openCLMemcpy2D(clCxt, m.data, m.step, temp, pitch, wholecols * m.elemSize(), wholerows, clMemcpyDeviceToHost, 3);
        openCLSafeCall(clReleaseMemObject(temp));
    }
    else
    {
        openCLMemcpy2D(clCxt, m.data, m.step, data, step, wholecols * elemSize(), wholerows, clMemcpyDeviceToHost);
    }

    Size wholesize;
    Point ofs;
    locateROI(wholesize, ofs);
    m.adjustROI(-ofs.y, ofs.y + rows - wholerows, -ofs.x, ofs.x + cols - wholecols);
}
void cv::ocl::oclMat::download(cv::Mat &m) const
{
    CV_DbgAssert(!this->empty());
    int t = type();
    //if(download_channels == 3)
    //t = CV_MAKETYPE(depth(), 3);
    m.create(wholerows, wholecols, t);

    //if(download_channels == 3)
    //{
    //int pitch = GPU_MATRIX_MALLOC_STEP(wholecols * 3 * m.elemSize1());
    //int err;
    //cl_mem temp = clCreateBuffer(clCxt->clContext,CL_MEM_READ_WRITE,
    //pitch*wholerows,0,&err);
    //CV_DbgAssert(err==0);

    //convert_C4C3(*this, temp, pitch/m.elemSize1());
    //openCLMemcpy2D(clCxt,m.data,m.step,temp,pitch,wholecols*m.elemSize(),wholerows,clMemcpyDeviceToHost);
    //}
    //else
    openCLMemcpy2D(clCxt, m.data, m.step, data, step, wholecols * elemSize(), wholerows, clMemcpyDeviceToHost);
    Size wholesize;
    Point ofs;
    locateROI(wholesize, ofs);
    m.adjustROI(-ofs.y, ofs.y + rows - wholerows, -ofs.x, ofs.x + cols - wholecols);
}
void cv::ocl::oclMat::download(cv::Mat &m) const
{
    CV_DbgAssert(!this->empty());
    //   int t = type();
    //   if(download_channels == 3)
    //{
    //	t = CV_MAKETYPE(depth(), 3);
    //}
    m.create(wholerows, wholecols, type());

    if(m.channels() == 3)
    {
        int pitch = wholecols * 3 * m.elemSize1();
        int tail_padding = m.elemSize1() * 3072;
        int err;
        cl_mem temp = clCreateBuffer((cl_context)clCxt->oclContext(), CL_MEM_READ_WRITE,
                                     (pitch * wholerows + tail_padding - 1) / tail_padding * tail_padding, 0, &err);
        openCLVerifyCall(err);

        convert_C4C3(*this, temp);
        openCLMemcpy2D(clCxt, m.data, m.step, temp, pitch, wholecols * m.elemSize(), wholerows, clMemcpyDeviceToHost, 3);
        //int* cputemp=new int[wholecols*wholerows * 3];
        //int* cpudata=new int[this->step*this->wholerows/sizeof(int)];
        //openCLSafeCall(clEnqueueReadBuffer(clCxt->impl->clCmdQueue, temp, CL_TRUE,
        //						0, wholecols*wholerows * 3* sizeof(int), cputemp, 0, NULL, NULL));
        //openCLSafeCall(clEnqueueReadBuffer(clCxt->impl->clCmdQueue, (cl_mem)data, CL_TRUE,
        //						0, this->step*this->wholerows, cpudata, 0, NULL, NULL));
        //for(int i=0;i<wholerows;i++)
        //{
        //	int *a = cputemp+i*wholecols * 3,*b = cpudata + i*this->step/sizeof(int);
        //	for(int j=0;j<wholecols;j++)
        //	{
        //		if((a[3*j] != b[4*j])||(a[3*j+1] != b[4*j+1])||(a[3*j+2] != b[4*j+2]))
        //			printf("rows=%d,cols=%d,cputtemp=%d,%d,%d;cpudata=%d,%d,%d\n",
        //			i,j,a[3*j],a[3*j+1],a[3*j+2],b[4*j],b[4*j+1],b[4*j+2]);
        //	}
        //}
        //delete []cputemp;
        //delete []cpudata;
        openCLSafeCall(clReleaseMemObject(temp));
    }
    else
    {
        openCLMemcpy2D(clCxt, m.data, m.step, data, step, wholecols * elemSize(), wholerows, clMemcpyDeviceToHost);
    }
    Size wholesize;
    Point ofs;
    locateROI(wholesize, ofs);
    m.adjustROI(-ofs.y, ofs.y + rows - wholerows, -ofs.x, ofs.x + cols - wholecols);
}
예제 #5
0
double BackgroundInitializationModule::sideMatch(cv::Mat ROI, cv::Mat block, bool isBlockImg)
{
	double SM_metric = 0.0;
	cv::Mat backup, vector;
	uchar *ptr_vector;
	cv::Size bgDimension;
	cv::Point ROIloc;
	bool growUp, growLeft, growRight, growBottom;

	if(isBlockImg)
	{
		ROI.copyTo(backup);
		block.copyTo(ROI);
	}

	ROI.locateROI(bgDimension, ROIloc);

	growUp = (ROIloc.y - 1 < 0)? false: true ;
	growLeft = (ROIloc.x - 1 < 0)? false: true ;
	growRight = (ROIloc.x + sizeBlock + 1 >= bgDimension.width)? false: true ;
	growBottom = (ROIloc.y + sizeBlock + 1  >= bgDimension.width)? false: true ;

	ROI.adjustROI(1,1,1,1); //grow 1 pixel in every direction
	if(growUp)
	{
		vector = block.row(0) - block.row(1);
		vector = vector.mul(vector);
		ptr_vector = vector.data;

		for(int i = 0; i < vector.rows*vector.cols; i++)
			SM_metric += ptr_vector[i];
	}
	if(growLeft)
	{
		vector = block.row(0) - block.row(1);
		vector = vector.mul(vector);
		ptr_vector = vector.data;

		for(int i = 0; i < vector.rows*vector.cols; i++)
			SM_metric += ptr_vector[i];
	}
	if(growRight)
	{
		vector = block.row(0) - block.row(1);
		vector = vector.mul(vector);
		ptr_vector = vector.data;

		for(int i = 0; i < vector.rows*vector.cols; i++)
			SM_metric += ptr_vector[i];
	}
	if(growBottom)
	{
		vector = block.row(0) - block.row(1);
		vector = vector.mul(vector);
		ptr_vector = vector.data;

		for(int i = 0; i < vector.rows*vector.cols; i++)
			SM_metric += ptr_vector[i];
	}


	if(isBlockImg)
		backup.copyTo(ROI);

	return SM_metric;
}