void PushbroomStereo::ProcessImages2(InputArray _leftImage, InputArray _rightImage, std::vector<Point3f> *pointVector3d, std::vector<Point3i> *pointVector2d, std::vector<uchar> *pointColors) 
{

    Mat leftImage = _leftImage.getMat();
    Mat rightImage = _rightImage.getMat();

    // make sure that the inputs are of the right type
    CV_Assert(leftImage.type() == CV_8UC1 && rightImage.type() == CV_8UC1);

    //Mat remapped_left(state.mapxL.rows, state.mapxL.cols, leftImage.depth());
    //Mat remapped_right(state.mapxR.rows, state.mapxR.cols, rightImage.depth());


	//INTEREST_OP步骤,拉普拉斯变换
    Mat laplacian_left(leftImage.rows, leftImage.cols, leftImage.depth());
    Mat laplacian_right(rightImage.rows, rightImage.cols, rightImage.depth());

	Laplacian(leftImage,laplacian_left, -1, 3, 1, 0, BORDER_DEFAULT);
	Laplacian(rightImage,laplacian_right, -1, 3, 1, 0, BORDER_DEFAULT);

	//imshow("Laplac_L", laplacian_left);
	//imshow("Laplac_R", laplacian_right);

	//while( 1 )
	//{
	//	waitKey( 100 );
	//}

	RunStereoPushbroomStereo2(leftImage, rightImage,laplacian_left,laplacian_right,	pointVector3d,pointVector2d,pointColors);


}
Пример #2
0
/**
 * Displays a very zoomed in version of the two pixel blocks being looked at
 *
 * @param left_image the left image
 * @param right_image the right image
 * @param left left coordinate of the box
 * @param top top coordinate of the box
 * @param state PushbroomStereoState containing stereo information
 * @param pushbroom_stereo stereo object so we can run GetSAD
 *
 */
void DisplayPixelBlocks(Mat left_image, Mat right_image, int left, int top, PushbroomStereoState state, PushbroomStereo *pushbroom_stereo) {
    if (left + state.blockSize > left_image.cols || top+state.blockSize > left_image.rows
        || left + state.blockSize > right_image.cols || top+state.blockSize > right_image.rows
        || left + state.disparity < 0) { // remember, disparity can be negative

        // invalid spot

        return;
    }

    Mat left_block = left_image.rowRange(top, top+state.blockSize).colRange(left, left+state.blockSize);
    Mat right_block = right_image.rowRange(top, top+state.blockSize).colRange(left+state.disparity, left+state.disparity+state.blockSize);


    Mat laplacian_left;
    Laplacian(left_image, laplacian_left, -1, 3, 1, 0, BORDER_DEFAULT);

    Mat laplacian_right;
    Laplacian(right_image, laplacian_right, -1, 3, 1, 0, BORDER_DEFAULT);

    // compute stats about block
    int left_interest, right_interest, raw_sad;
    int sad = pushbroom_stereo->GetSAD(left_image, right_image, laplacian_left, laplacian_right, left, top,
        state, &left_interest, &right_interest, &raw_sad);

    float diff_score = 100*(float)abs(left_interest - right_interest)/(float)(left_interest+right_interest);

    // make the blocks visible by making them huge
    const int scale_factor = 100;

    Size output_size = Size(state.blockSize * scale_factor, state.blockSize * scale_factor);
    resize(left_block, left_block, output_size, 0, 0, INTER_NEAREST);
    resize(right_block, right_block, output_size, 0, 0, INTER_NEAREST);

    char sad_str_char[100], left_interest_char[100], right_interest_char[100],
        diff_score_char[100], raw_sad_char[100];
    sprintf(sad_str_char, "SAD = %d", sad);
    sprintf(left_interest_char, "Left interest = %d", left_interest);
    sprintf(right_interest_char, "Right interest = %d", right_interest);
    sprintf(raw_sad_char, "Raw sad = %d", raw_sad);
    sprintf(diff_score_char, "Diff score = %.02f", diff_score);

    putText(right_block, raw_sad_char, Point(310, 425), FONT_HERSHEY_PLAIN, 1, 0);
    putText(right_block, sad_str_char, Point(400, 445), FONT_HERSHEY_PLAIN, 1, 0);
    putText(right_block, left_interest_char, Point(310, 465), FONT_HERSHEY_PLAIN, 1, 0);
    putText(right_block, right_interest_char, Point(305, 485), FONT_HERSHEY_PLAIN, 1, 0);
    putText(right_block, diff_score_char, Point(305, 495), FONT_HERSHEY_PLAIN, 1, 0);

    imshow("Left Block", left_block);
    imshow("Right Block", right_block);



}
Пример #3
0
void edgeDetect(Mat& img) {
	GaussianBlur(img, img, Size(3, 3), 0, 0);
	Mat tmp;
	img.copyTo(tmp);
	Canny(img, img, 30, 100, 3, true);
	bitwise_not(img, img);
	erode(img, img, getStructuringElement(MORPH_ELLIPSE, Size(dilation_size + 1, dilation_size + 1), Point(dilation_size, dilation_size)));

	if(loaded) {
		std::vector<Rect> faces;
		cvtColor(tmp, tmp, COLOR_BGR2GRAY );
		equalizeHist( tmp, tmp);
		face_cascade.detectMultiScale(tmp, faces, 1.1, 2, 0, Size(80, 80));

		for( size_t i = 0; i < faces.size(); i++ )  {
		        Mat faceROI = tmp(faces[i]);
		        Laplacian(faceROI, faceROI, CV_16S, 3, 2.5, 1, BORDER_DEFAULT);
		        threshold(faceROI, faceROI, 7, 255, THRESH_BINARY_INV);
		        convertScaleAbs(faceROI, faceROI);
		        dilate(faceROI, faceROI, getStructuringElement(MORPH_ELLIPSE, Size(2, 2), Point(1, 1)));
		        faceROI.copyTo(img(faces[i]));
		        rectangle(img, faces[i], Scalar( 255, 190, 0 ));

		    }
	}
	cvtColor(img, img, CV_GRAY2BGR);

}
Пример #4
0
KDvoid Laplace ( KDint nIdx )
{
	Mat		tSrc;
	Mat		tDst;

	Mat		tGray;
	Mat		tTemp;

	KDint	nSize;
	KDint	nScale;
	KDint	nDelta;
	KDint	nDepth;

	// Load the source image
	tSrc = imread ( "/res/image/lena.jpg" ); 

	nSize  = 3;
	nScale = 1;
	nDelta = 0;
	nDepth = CV_16S;

	// Reduce noise
	GaussianBlur ( tSrc, tSrc, Size ( 3, 3 ), 0, 0, BORDER_DEFAULT );

	// Convert it to gray
	cvtColor ( tSrc, tGray, CV_RGB2GRAY );

	// Apply Laplace function
	Laplacian ( tGray, tTemp, nDepth, nSize, nScale, nDelta, BORDER_DEFAULT );
	convertScaleAbs ( tTemp, tDst );

	g_pController->setFrame ( 1, tSrc );
	g_pController->setFrame ( 2, tDst );
}
void SpecificWorker::compute()
{
	try
	{
		vector<string> names;
		names.push_back("default");
		RoboCompRGBDBus::ImageMap imgs;
		rgbdbus_proxy->getImages(names, imgs);
		Mat frame(imgs["default"].camera.colorHeight, imgs["default"].camera.colorWidth, CV_8UC3,  &(imgs["default"].colorImage)[0]);
		drawQtImage((const uchar *)(&(imgs["default"].colorImage)[0]), imgs["default"].camera.colorWidth, imgs["default"].camera.colorHeight, QImage::Format_RGB888, label);
		
		/// Apply Laplace function
		Mat gray, dst, abs_dst;
		cvtColor( frame, gray, CV_RGB2GRAY );
		Laplacian( gray, dst, CV_16S, 3, 1, 0, BORDER_DEFAULT );
		convertScaleAbs( dst, abs_dst );
		drawQtImage( (const uchar *)(abs_dst.data), imgs["default"].camera.colorWidth, imgs["default"].camera.colorHeight, QImage::Format_Indexed8, label_edges);
		
		printFPS();
		//imshow("img", frame);
	}
	catch(const Ice::Exception &e)
	{
		std::cout << "Error reading from Camera" << e << std::endl;
	}
}
Пример #6
0
/*
  update the matrix of equaiton Teqn, and then solve it
*/
void Teqn_update(void)
{
    
    EulerImplicit(m, rho->data, T->old, dt);
    Laplacian(m, diff_coef->data);
    solve(Teqn, T->data);
}
Пример #7
0
void EdgedetectDialog::edge_detect(void)
{
    Laplacian(gray_image, *pimage, image.depth(), log_ksize, log_scale, log_delta, cv::BORDER_DEFAULT);
    threshold(*pimage, *pimage, log_thr, 255, 0);

    emit statusChanged();
}
Пример #8
0
void procOCL_I2I(int texIn, int texOut, int w, int h)
{
    if(!haveOpenCL) return;

    LOGD("procOCL_I2I(%d, %d, %d, %d)", texIn, texOut, w, h);
    cl::ImageGL imgIn (theContext, CL_MEM_READ_ONLY,  GL_TEXTURE_2D, 0, texIn);
    cl::ImageGL imgOut(theContext, CL_MEM_WRITE_ONLY, GL_TEXTURE_2D, 0, texOut);
    std::vector < cl::Memory > images;
    images.push_back(imgIn);
    images.push_back(imgOut);

    int64_t t = getTimeMs();
    theQueue.enqueueAcquireGLObjects(&images);
    theQueue.finish();
    LOGD("enqueueAcquireGLObjects() costs %d ms", getTimeInterval(t));

    t = getTimeMs();
    cl::Kernel Laplacian(theProgI2I, "Laplacian"); //TODO: may be done once
    Laplacian.setArg(0, imgIn);
    Laplacian.setArg(1, imgOut);
    theQueue.finish();
    LOGD("Kernel() costs %d ms", getTimeInterval(t));

    t = getTimeMs();
    theQueue.enqueueNDRangeKernel(Laplacian, cl::NullRange, cl::NDRange(w, h), cl::NullRange);
    theQueue.finish();
    LOGD("enqueueNDRangeKernel() costs %d ms", getTimeInterval(t));

    t = getTimeMs();
    theQueue.enqueueReleaseGLObjects(&images);
    theQueue.finish();
    LOGD("enqueueReleaseGLObjects() costs %d ms", getTimeInterval(t));
}
Пример #9
0
int physics_run(real t)
{
  //output.write("Running %e\n", t);
  // Run communications
  comms.run();

  // Density
  
  F_N = -V_dot_Grad(V, N) - N*Div(V);
 
  //output.write("N ");
 
  // Velocity 
  
  F_V = -V_dot_Grad(V, V) - Grad(P)/N + g;

  if(sub_initial) {
    F_V += Grad(P0)/N0 - g;
  }

  //output.write("V ");

  if(include_viscosity) {
    // Add viscosity
    
    F_V.y += nu*Laplacian(V.y);
    F_V.z += nu*Laplacian(V.z);

    //output.write("nu ");
  }
  
  // Pressure

  F_P = -V_dot_Grad(V, P) - gamma_ratio*P*Div(V);

  //output.write("P\n");

  // Set boundary conditions
  apply_boundary(F_N, "density");
  apply_boundary(F_P, "pressure");
  F_V.to_contravariant();
  apply_boundary(F_V, "v");

  //output.write("finished\n");

  return 0;
}
Пример #10
0
int physics_run(real t)
{
  // Run communications
  comms.run();

  msg_stack.push("F_rho");
  
  F_rho = -V_dot_Grad(v, rho) - rho*Div(v);

  msg_stack.pop(); msg_stack.push("F_p");

  F_p = -V_dot_Grad(v, p) - gamma*p*Div(v);
  
  msg_stack.pop(); msg_stack.push("F_v");
  
  F_v = -V_dot_Grad(v, v) + ((Curl(B)^B) - Grad(p))/rho;

  if(include_viscos) {
    F_v.x += viscos * Laplacian(F_v.x);
    F_v.y += viscos * Laplacian(F_v.y);
    F_v.z += viscos * Laplacian(F_v.z);
  }
  
  msg_stack.pop(); msg_stack.push("F_B");
  
  F_B = Curl(v^B);

  // boundary conditions

  apply_boundary(F_rho, "density");
  apply_boundary(F_p, "pressure");
  F_v.to_covariant();
  apply_boundary(F_v, "v");
  F_B.to_contravariant();
  apply_boundary(F_B, "B");

  msg_stack.pop(); msg_stack.push("DivB");
  
  divB = Div(B); // Just for diagnostic
  bndry_inner_zero(divB);
  bndry_sol_zero(divB);

  return 0;
}
Пример #11
0
void edgeDetectLaplacian(Mat& img) {
	GaussianBlur(img, img, Size(3, 3), 0, 0);
	cvtColor(img, img, CV_RGB2GRAY);
	Laplacian(img, img, CV_16S, 3, 2, 1, BORDER_DEFAULT);
	threshold(img, img, 7, 255, THRESH_BINARY_INV);
	convertScaleAbs(img, img);
	dilate(img, img,
			getStructuringElement(MORPH_ELLIPSE, Size(2, 2), Point(1, 1)));
	cvtColor(img, img, CV_GRAY2BGR);
}
tmp<faMatrix<Type> >
laplacian
(
    const tmp<areaScalarField>& tgamma,
    GeometricField<Type, faPatchField, areaMesh>& vf
)
{
    tmp<faMatrix<Type> > Laplacian(fam::laplacian(tgamma(), vf));
    tgamma.clear();
    return Laplacian;
}
double Wavefunction::Laplace_Ratio(const mat &r, const int number_particles, double alpha, int atom_nr)
{
    double Ratio = 0;

    //Slater up biten
    Spin_Up_Slater_det = slater_reduced_det(r, 0, alpha, number_particles, atom_nr);
    Spin_Up_Slater_det_Inv = inv(Spin_Up_Slater_det);

    //Slater ned biten
    Spin_Down_Slater_det = slater_reduced_det(r, 1, alpha, number_particles, atom_nr);
    Spin_Down_Slater_det_Inv = inv(Spin_Down_Slater_det);

    for (int i = 0; i < number_particles/2; i++){
        for (int j = 0; j < number_particles/2; j++){
            Ratio += Laplacian(r, i, j, alpha, atom_nr) * Spin_Up_Slater_det_Inv(j,i)
                    + Laplacian(r, (i + number_particles/2), j, alpha, atom_nr) * Spin_Down_Slater_det_Inv(j,i);
        }
    }
    return Ratio;
}
tmp<fvMatrix<Type> >
laplacian
(
    const tmp<GeometricField<GType, fvPatchField, volMesh> >& tgamma,
    GeometricField<Type, fvPatchField, volMesh>& vf
)
{
    tmp<fvMatrix<Type> > Laplacian(fvm::laplacian(tgamma(), vf));
    tgamma.clear();
    return Laplacian;
}
Пример #15
0
Mat IPS_simple::applyLaplacian(Mat src){
    Mat dst = src.clone();

    clock_t startStep = clock();
    Laplacian( src, dst, Constants::LAPLACE_DDEPTH, Constants::LAPLACE_KERNEL_SIZE, Constants::LAPLACE_SCALE,
               Constants::LAPLACE_DELTA, BORDER_DEFAULT );
    clock_t stopStep = clock();
    double elapsedStep = (double)difftime(startStep, stopStep) * 1000.0 / CLOCKS_PER_SEC;
    printf("Tiempo de ejecucion de Laplacian:\t%f\tms \n", std::abs(elapsedStep) );

    return dst;
}
static void computeEdgeMap( const Mat &image, Mat &edges )
{
    //get edge map
    Mat gray;
    cvtColor( image, gray, CV_BGR2GRAY );
    const int MEDIAN_BLUR_FILTER_SIZE = 7;
    medianBlur( gray, gray, MEDIAN_BLUR_FILTER_SIZE );

    const int LAPLACIAN_FILTER_SIZE = 5;
    Laplacian( gray, edges, CV_8U, LAPLACIAN_FILTER_SIZE );
    //***************

}
Пример #17
0
tmp<GeometricField<Type, fvPatchField, volMesh> >
laplacian
(
    const tmp<GeometricField<Type, fvPatchField, volMesh> >& tvf
)
{
    tmp<GeometricField<Type, fvPatchField, volMesh> > Laplacian
    (
        fvc::laplacian(tvf())
    );
    tvf.clear();
    return Laplacian;
}
Пример #18
0
void testlap(LevelData<double >& a_phi, double a_dx,char* a_str)
{
  double coef = 1./(a_dx*a_dx);
  Stencil<double> Laplacian(make_pair(getZeros(),-DIM*2*coef));
  BoxLayout bl = a_phi.getBoxLayout();
  
  for (int dir = 0; dir < DIM ; dir++)
    {
      Point edir = getUnitv(dir);
      Stencil<double> plus(make_pair(Shift(edir),coef));
      Stencil<double> minus(make_pair(Shift(edir*(-1)),coef));
      Laplacian = Laplacian + minus + plus;
    }
  
  a_phi.exchange();
  RectMDArray<double> LPhi00(bl.getDomain());
  for (BLIterator blit(bl); blit != blit.end(); ++blit)
    {
      LPhi00 |= Laplacian(a_phi[*blit],bl[*blit]);
    }
   MDWrite(a_str,LPhi00);
};
Пример #19
0
tmp<GeometricField<Type, fvPatchField, volMesh> > laplacian
(
    const tmp<GeometricField<GType, fvsPatchField, surfaceMesh> >& tgamma,
    const tmp<GeometricField<Type, fvPatchField, volMesh> >& tvf
)
{
    tmp<GeometricField<Type, fvPatchField, volMesh> > Laplacian
    (
        fvc::laplacian(tgamma(), tvf())
    );
    tgamma.clear();
    tvf.clear();
    return Laplacian;
}
Пример #20
0
tmp<GeometricField<Type, fvPatchField, volMesh> >
laplacian
(
    const dimensioned<GType>& gamma,
    const tmp<GeometricField<Type, fvPatchField, volMesh> >& tvf
)
{
    tmp<GeometricField<Type, fvPatchField, volMesh> > Laplacian
    (
        fvc::laplacian(gamma, tvf())
    );
    tvf.clear();
    return Laplacian;
}
Пример #21
0
int laplacian_cpu(const unsigned char* src, int width, int height, int ksize, unsigned char* dst, float* elapsed_time)
{
	int ret{ -1 };
	// ksize == 1: kernel={ 0, 1, 0, 1, -4, 1, 0, 1, 0 }
	// ksize == 3: kernel={ 2, 0, 2, 0, -8, 0, 2, 0, 2 }
	CHECK(ksize == 1 || ksize == 3);
	//TIME_START_CPU

	ret = Laplacian(src, dst, width, height, ksize);

	//TIME_END_CPU

	return ret;
}
Пример #22
0
tmp<GeometricField<Type, faPatchField, areaMesh> > laplacian
(
    const tmp<edgeScalarField>& tgamma,
    const tmp<GeometricField<Type, faPatchField, areaMesh> >& tvf
)
{
    tmp<GeometricField<Type, faPatchField, areaMesh> > Laplacian
    (
        fac::laplacian(tgamma(), tvf())
    );
    tgamma.clear();
    tvf.clear();
    return Laplacian;
}
Пример #23
0
tmp<GeometricField<Type, faPatchField, areaMesh> >
laplacian
(
    const dimensionedScalar& gamma,
    const tmp<GeometricField<Type, faPatchField, areaMesh> >& tvf
)
{
    tmp<GeometricField<Type, faPatchField, areaMesh> > Laplacian
    (
        fac::laplacian(gamma, tvf())
    );
    tvf.clear();
    return Laplacian;
}
Пример #24
0
tmp<GeometricField<Type, faPatchField, areaMesh> >
laplacian
(
    const tmp<GeometricField<Type, faPatchField, areaMesh> >& tvf,
    const word& name
)
{
    tmp<GeometricField<Type, faPatchField, areaMesh> > Laplacian
    (
        fac::laplacian(tvf(), name)
    );
    tvf.clear();
    return Laplacian;
}
Пример #25
0
tmp<GeometricField<Type, faPatchField, areaMesh> >
laplacian
(
    const tmp<edgeScalarField>& tgamma,
    const GeometricField<Type, faPatchField, areaMesh>& vf,
    const word& name
)
{
    tmp<GeometricField<Type, faPatchField, areaMesh> > Laplacian
    (
        fac::laplacian(tgamma(), vf, name)
    );
    tgamma.clear();
    return Laplacian;
}
Пример #26
0
tmp<GeometricField<Type, fvPatchField, volMesh> >
laplacian
(
    const tmp<GeometricField<GType, fvPatchField, volMesh> >& tgamma,
    const GeometricField<Type, fvPatchField, volMesh>& vf,
    const word& name
)
{
    tmp<GeometricField<Type, fvPatchField, volMesh> > Laplacian
    (
        fvc::laplacian(tgamma(), vf, name)
    );
    tgamma.clear();
    return Laplacian;
}
Пример #27
0
tmp<GeometricField<Type, fvPatchField, volMesh> >
laplacian
(
    const GeometricField<GType, fvsPatchField, surfaceMesh>& gamma,
    const tmp<GeometricField<Type, fvPatchField, volMesh> >& tvf,
    const word& name
)
{
    tmp<GeometricField<Type, fvPatchField, volMesh> > Laplacian
    (
        fvc::laplacian(gamma, tvf(), name)
    );
    tvf.clear();
    return Laplacian;
}
Пример #28
0
cv::Mat laneTracker::cvLaplicain()
{
  cv::Mat src, dst, abs_dst;

  GaussianBlur(gray_, src, cv::Size(5,5), 0, 0);

  int kernel_size = 3;
  int scale = 1;
  int delta = 0;
  int ddepth = CV_16S;
  Laplacian(src, dst, ddepth, kernel_size, scale, delta, cv::BORDER_DEFAULT);
  convertScaleAbs(dst, abs_dst);

  return abs_dst;
}
Пример #29
0
Laplacian compute_laplacian(RandomAccessIterator begin, 
			RandomAccessIterator end,const Neighbors& neighbors, 
			DistanceCallback callback, ScalarType width)
{
	SparseTriplets sparse_triplets;

	timed_context context("Laplacian computation");
	const IndexType k = neighbors[0].size();
	sparse_triplets.reserve((k+1)*(end-begin));

	DenseVector D = DenseVector::Zero(end-begin);
	for (RandomAccessIterator iter=begin; iter!=end; ++iter)
	{
		const LocalNeighbors& current_neighbors = neighbors[iter-begin];

		for (IndexType i=0; i<k; ++i)
		{
			ScalarType distance = callback(*iter,begin[current_neighbors[i]]);
			ScalarType heat = exp(-distance*distance/width);
			D(iter-begin) += heat;
			D(current_neighbors[i]) += heat;
			sparse_triplets.push_back(SparseTriplet(current_neighbors[i],(iter-begin),-heat));
			sparse_triplets.push_back(SparseTriplet((iter-begin),current_neighbors[i],-heat));
		}
	}
	for (IndexType i=0; i<(end-begin); ++i)
		sparse_triplets.push_back(SparseTriplet(i,i,D(i)));

#ifdef EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET
	Eigen::DynamicSparseMatrix<ScalarType> dynamic_weight_matrix(end-begin,end-begin);
	dynamic_weight_matrix.reserve(sparse_triplets.size());
	for (SparseTriplets::const_iterator it=sparse_triplets.begin(); it!=sparse_triplets.end(); ++it)
		dynamic_weight_matrix.coeffRef(it->col(),it->row()) += it->value();
	SparseWeightMatrix weight_matrix(dynamic_weight_matrix);
#else
	SparseWeightMatrix weight_matrix(end-begin,end-begin);
	weight_matrix.setFromTriplets(sparse_triplets.begin(),sparse_triplets.end());
#endif

	return Laplacian(weight_matrix,DenseDiagonalMatrix(D));
}
Пример #30
0
/* Computes a bounding rectangle for the object according to its borders */
Rect refitToBorders(Mat region) {
    Mat img;
    cvtColor(region, img, CV_BGR2HSV);
    medianBlur(img, img, 11);
    Laplacian(img, img, -1, 3);
    Canny(img, img, 100, 200);
    int minX = img.cols, maxX = 0, minY = img.rows, maxY = 0;
    for (size_t x = 0; x < img.cols; x++) {
        for (size_t y = 0; y < img.rows; y++) {
            if (!img.at<uchar>(y, x))
                continue;
            if (x < minX)
               minX = x;
            if (x > maxX)
               maxX = x;
            if (y < minY)
               minY = y;
            if (y > maxY)
               maxY = y;
        }
    }
    return Rect(Point(minX, minY), Point(maxX, maxY));
}