Esempio n. 1
0
Point CylindricalWarperGpu::warp(const cuda::GpuMat & src, InputArray K, InputArray R, int interp_mode, int border_mode,
                                 cuda::GpuMat & dst)
{
    Rect dst_roi = buildMaps(src.size(), K, R, d_xmap_, d_ymap_);
    dst.create(dst_roi.height + 1, dst_roi.width + 1, src.type());
    cuda::remap(src, dst, d_xmap_, d_ymap_, interp_mode, border_mode);
    return dst_roi.tl();
}
void build_psf_fft(int width, int height, float ffwhm_x)
{
    PSFR = Mat::zeros(ImageR.size(), CV_32F);
   

    int hs = fwhm_x * 0.3; 
    Mat kernelX = getGaussianKernel(hs * 10, ffwhm_x);
    Mat kernelY = getGaussianKernel(hs * 10, ffwhm_x);
    Mat kernel = kernelX * kernelY.t(); 
    //Mat kernel;


    //Mat kernel;
    //resize(psf_file, kernel, Size(0, 0), 23.0/fwhm_x, 23.0/fwhm_x, INTER_AREA);
   
    hs = kernel.cols; 
    
    int dy = height - hs;
    int dx = width - hs;

    pow(kernel, power/100.0, kernel); 
    imshow("kernel", kernel * 235);
    copyMakeBorder(kernel, PSFR,
		   dy/2,
		   dy-(dy/2),
		   dx/2,
		   dx-(dx/2),
		   BORDER_CONSTANT, Scalar::all(0.0));

    //imshow("kernel", PSFR);
 
    PSFR.convertTo(PSFR, CV_32F);
    PSFI = Mat::zeros(PSFR.size(), CV_32F);
 
    Mat psf_planes[] = {PSFR, PSFI};
   

    gPSFR.upload(PSFR);
    gPSFI.upload(PSFI); 
    
    Scalar psum = cuda::sum(gPSFR);
    cuda::multiply(gPSFR, 1.0 / psum[0], gPSFR);
    
    psum = cuda::sum(gPSFR);
    Mat complexPSF;
   
    cuda::GpuMat gpPSF;
 
    merge(psf_planes, 2, complexPSF);
    gpPSF.upload(complexPSF);
    cuda::dft(gpPSF, gpPSF, gpPSF.size());
    gpPSF.download(complexPSF); 
    split(complexPSF, psf_planes);
    //imshow("fft", PSFR);
}
Esempio n. 3
0
TensorWrapper::TensorWrapper(cuda::GpuMat & mat, THCState *state) {

    this->definedInLua = false;

    if (mat.empty()) {
        this->typeCode = CV_CUDA;
        this->tensorPtr = nullptr;
        return;
    }

    this->typeCode = CV_CUDA;

    THCudaTensor *outputPtr = THCudaTensor_new(state);

    // Build new storage on top of the Mat
    outputPtr->storage = THCudaStorage_newWithData(
            state,
            reinterpret_cast<float *>(mat.data),
            mat.step * mat.rows * mat.channels() / cv::getElemSize(mat.depth())
    );

    int sizeMultiplier;
    if (mat.channels() == 1) {
        outputPtr->nDimension = 2;
        sizeMultiplier = cv::getElemSize(mat.depth());
    } else {
        outputPtr->nDimension = 3;
        sizeMultiplier = mat.elemSize1();
    }

    outputPtr->size = static_cast<long *>(THAlloc(sizeof(long) * outputPtr->nDimension));
    outputPtr->stride = static_cast<long *>(THAlloc(sizeof(long) * outputPtr->nDimension));

    if (mat.channels() > 1) {
        outputPtr->size[2] = mat.channels();
        outputPtr->stride[2] = 1;
    }

    outputPtr->size[0] = mat.rows;
    outputPtr->size[1] = mat.cols;

    outputPtr->stride[0] = mat.step / sizeMultiplier;
    outputPtr->stride[1] = mat.channels();

    outputPtr->storageOffset = 0;

    // Make OpenCV treat underlying data as user-allocated
    mat.refcount = nullptr;

    this->tensorPtr = reinterpret_cast<THByteTensor *>(outputPtr);
}
void CCubicGrids::extractRTFromBuffer(const cuda::GpuMat& cvgmSumBuf_, Eigen::Matrix3f* peimRw_, Eigen::Vector3f* peivTw_) const{
	Mat cvmSumBuf;
	cvgmSumBuf_.download(cvmSumBuf);
	double* aHostTmp = (double*)cvmSumBuf.data;
	//declare A and b
	Eigen::Matrix<double, 6, 6, Eigen::RowMajor> A;
	Eigen::Matrix<double, 6, 1> b;
	//retrieve A and b from cvmSumBuf
	short sShift = 0;
	for (int i = 0; i < 6; ++i){   // rows
		for (int j = i; j < 7; ++j) { // cols + b
			double value = aHostTmp[sShift++];
			if (j == 6)       // vector b
				b.data()[i] = value;
			else
				A.data()[j * 6 + i] = A.data()[i * 6 + j] = value;
		}//for each col
	}//for each row
	//checking nullspace
	double dDet = A.determinant();
	if (fabs(dDet) < 1e-15 || dDet != dDet){
		if (dDet != dDet)
			PRINTSTR("Failure -- dDet cannot be qnan. ");
		//reset ();
		return;
	}//if dDet is rational
	//float maxc = A.maxCoeff();

	Eigen::Matrix<float, 6, 1> result = A.llt().solve(b).cast<float>();
	//Eigen::Matrix<float, 6, 1> result = A.jacobiSvd(ComputeThinU | ComputeThinV).solve(b);

	float alpha = result(0);
	float beta = result(1);
	float gamma = result(2);

	Eigen::Matrix3f Rinc = (Eigen::Matrix3f)Eigen::AngleAxisf(gamma, Eigen::Vector3f::UnitZ()) * Eigen::AngleAxisf(beta, Eigen::Vector3f::UnitY()) * Eigen::AngleAxisf(alpha, Eigen::Vector3f::UnitX());
	Eigen::Vector3f tinc = result.tail<3>();

	//compose
	//eivTwCur   = Rinc * eivTwCur + tinc;
	//eimrmRwCur = Rinc * eimrmRwCur;
	Eigen::Vector3f eivTinv = -peimRw_->transpose()* (*peivTw_);
	Eigen::Matrix3f eimRinv = peimRw_->transpose();
	eivTinv = Rinc * eivTinv + tinc;
	eimRinv = Rinc * eimRinv;
	*peivTw_ = -eimRinv.transpose() * eivTinv;
	*peimRw_ = eimRinv.transpose();
}
Esempio n. 5
0
inline
Mat::Mat(const cuda::GpuMat& m)
    : flags(0), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows)
{
    m.download(*this);
}
Esempio n. 6
0
 void unmapFrame(cuda::GpuMat& frame)
 {
     cuSafeCall( cuvidUnmapVideoFrame(decoder_, (CUdeviceptr) frame.data) );
     frame.release();
 }