当前位置: 首页>>代码示例>>Java>>正文


Java Imgproc.threshold方法代码示例

本文整理汇总了Java中org.opencv.imgproc.Imgproc.threshold方法的典型用法代码示例。如果您正苦于以下问题:Java Imgproc.threshold方法的具体用法?Java Imgproc.threshold怎么用?Java Imgproc.threshold使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.opencv.imgproc.Imgproc的用法示例。


在下文中一共展示了Imgproc.threshold方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: adaptativeProcess

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public static Mat adaptativeProcess(Mat img){
	Mat im = new Mat();
	Imgproc.threshold(img,im,120,255,Imgproc.THRESH_TRUNC);
	im = Thresholding.adaptativeThresholding(im);
	Imgproc.medianBlur(im,im,7);
	Mat threshImg = Thresholding.InvertImageColor(im);
	Thresholding.gridDetection(threshImg);
	
		Mat mat = Mat.zeros(4,2,CvType.CV_32F);
	mat.put(0,0,0); mat.put(0,1,512);
	mat.put(1,0,0); mat.put(1,1,0);
	mat.put(2,0,512); mat.put(2,1,0);
	mat.put(3,0,512); mat.put(3,1,512);
	
	mat = Imgproc.getPerspectiveTransform(Thresholding.grid,mat);
	
	Mat M = new Mat();
	
	Imgproc.warpPerspective(threshImg,M,mat, new Size(512,512));
	
	Imgproc.medianBlur(M,M,3);
	Imgproc.threshold(M,M,254,255,Imgproc.THRESH_BINARY);
	
	return Thresholding.InvertImageColor(M);
}
 
开发者ID:Sanahm,项目名称:SudoCAM-Ku,代码行数:26,代码来源:Thresholding.java

示例2: doBackgroundRemovalAbsDiff

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
private Mat doBackgroundRemovalAbsDiff(Mat currFrame) {
    Mat greyImage = new Mat();
    Mat foregroundImage = new Mat();

    if (oldFrame == null)
        oldFrame = currFrame;

    Core.absdiff(currFrame, oldFrame, foregroundImage);
    Imgproc.cvtColor(foregroundImage, greyImage, Imgproc.COLOR_BGR2GRAY);

    int thresh_type = Imgproc.THRESH_BINARY_INV;
    if (inverse.isSelected())
        thresh_type = Imgproc.THRESH_BINARY;

    Imgproc.threshold(greyImage, greyImage, 10, 255, thresh_type);
    currFrame.copyTo(foregroundImage, greyImage);

    oldFrame = currFrame;
    return foregroundImage;

}
 
开发者ID:Evegen55,项目名称:main_carauto_board,代码行数:22,代码来源:MagicTabController.java

示例3: DifferenceOfGaussian

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public void DifferenceOfGaussian() {
    Mat grayMat = new Mat();
    Mat blur1 = new Mat();
    Mat blur2 = new Mat();

    //Converting the image to grayscale
    Imgproc.cvtColor(originalMat, grayMat, Imgproc.COLOR_BGR2GRAY);

    Imgproc.GaussianBlur(grayMat, blur1, new Size(15, 15), 5);
    Imgproc.GaussianBlur(grayMat, blur2, new Size(21, 21), 5);

    //Subtracting the two blurred images
    Mat DoG = new Mat();
    Core.absdiff(blur1, blur2, DoG);

    //Inverse Binary Thresholding
    Core.multiply(DoG, new Scalar(100), DoG);
    Imgproc.threshold(DoG, DoG, 50, 255, Imgproc.THRESH_BINARY_INV);

    //Converting Mat back to Bitmap
    Utils.matToBitmap(DoG, currentBitmap);
    imageView.setImageBitmap(currentBitmap);
}
 
开发者ID:johnhany,项目名称:MOAAP,代码行数:24,代码来源:MainActivity.java

示例4: enhancement

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
/**
 * Enhance the image after ridge filter.
 * Apply mask, binary threshold, thinning, ..., etc.
 */
private void enhancement(Mat source, Mat result, int blockSize, int rows, int cols, int padding) {
    Mat MatSnapShotMask = snapShotMask(rows, cols, padding);
    Mat paddedMask = imagePadding(MatSnapShotMask, blockSize);

    if (BuildConfig.DEBUG && !paddedMask.size().equals(source.size())) {
        throw new RuntimeException("Incompatible sizes of image and mask");
    }

    // apply the original mask to get rid of extras
    Core.multiply(source, paddedMask, result, 1.0, CvType.CV_8UC1);

    // apply binary threshold
    Imgproc.threshold(result, result, 0, 255, Imgproc.THRESH_BINARY);
}
 
开发者ID:jorenham,项目名称:fingerblox,代码行数:19,代码来源:ImageProcessing.java

示例5: leviRedFilter

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public void leviRedFilter (Mat input, Mat mask, double threshold){


        Imgproc.cvtColor(input, input, Imgproc.COLOR_RGB2Lab);
        Imgproc.GaussianBlur(input,input,new Size(3,3),0);
        Core.split(input, channels);
        Imgproc.threshold(channels.get(1), mask, threshold, 255, Imgproc.THRESH_BINARY);

        for(int i=0;i<channels.size();i++){
            channels.get(i).release();
        }
    }
 
开发者ID:GTHSRobotics,项目名称:DogeCV,代码行数:13,代码来源:LeviColorFilter.java

示例6: leviBlueFilter

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public void leviBlueFilter (Mat input, Mat mask){
    List<Mat> channels = new ArrayList<>();

    Imgproc.cvtColor(input, input, Imgproc.COLOR_RGB2Lab);
    Imgproc.GaussianBlur(input,input,new Size(3,3),0);
    Core.split(input, channels);
    Imgproc.threshold(channels.get(1), mask, 145, 255, Imgproc.THRESH_BINARY);

    for(int i=0;i<channels.size();i++){
        channels.get(i).release();
    }
}
 
开发者ID:GTHSRobotics,项目名称:DogeCV,代码行数:13,代码来源:LeviColorFilter.java

示例7: bin_second

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public static Mat bin_second(Mat input) {
	final Mat gray = new Mat();
	Imgproc.cvtColor(input, gray, Imgproc.COLOR_RGB2GRAY);
	final Mat binImg = new Mat();
	Imgproc.threshold(gray, binImg, 0, 255, Imgproc.THRESH_OTSU + Imgproc.THRESH_BINARY_INV);
	// Imgproc.adaptiveThreshold(gray, binImg, 255,
	// Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C, Imgproc.THRESH_BINARY, 11, 0);
	return binImg;
}
 
开发者ID:zylo117,项目名称:SpotSpotter,代码行数:10,代码来源:Binaryzation.java

示例8: binarize

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
/**
* Method for image binarization
* @parm img image to process
* @parm flag precize which method to 
* @return imB binarized image
* @see org.opencv.imgproc.Imgproc #threshold(Mat,int)
*/
public static Mat binarize(Mat img, int flag){
	Mat imB = new Mat();
	if(flag == Imgproc.THRESH_BINARY)
		Imgproc.threshold(img,imB,0,255,Imgproc.THRESH_BINARY);
	if(flag == Imgproc.THRESH_OTSU)
		Imgproc.threshold(img,imB,0,255,Imgproc.THRESH_BINARY+Imgproc.THRESH_OTSU);
	if(flag == Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C)
		Imgproc.adaptiveThreshold(img,imB,255,Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C,Imgproc.THRESH_BINARY,7,2);
	if(flag == Imgproc.ADAPTIVE_THRESH_MEAN_C)
		Imgproc.adaptiveThreshold(img,imB,255,Imgproc.ADAPTIVE_THRESH_MEAN_C,Imgproc.THRESH_BINARY,7,2);
	return imB;
}
 
开发者ID:Sanahm,项目名称:SudoCAM-Ku,代码行数:20,代码来源:Processing.java

示例9: getCanny

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
protected Mat getCanny(Mat gray) {
  Mat threshold = new Mat();
  Mat canny = new Mat();
  // last paramter 8 is using OTSU algorithm
  double high_threshold = Imgproc.threshold(gray, threshold, 0, 255, 8);
  double low_threshold = high_threshold * 0.5;
  Imgproc.Canny(gray, canny, low_threshold, high_threshold);
  return canny;
}
 
开发者ID:beast,项目名称:react-native-scan-doc,代码行数:10,代码来源:RNScanDocModule.java

示例10: doBackgroundRemoval

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
/**
 * Perform the operations needed for removing a uniform background
 *
 * @param frame the current frame
 * @return an image with only foreground objects
 */
private Mat doBackgroundRemoval(Mat frame) {
    // init
    Mat hsvImg = new Mat();
    List<Mat> hsvPlanes = new ArrayList<>();
    Mat thresholdImg = new Mat();

    int thresh_type = Imgproc.THRESH_BINARY_INV;
    if (inverse.isSelected())
        thresh_type = Imgproc.THRESH_BINARY;

    // threshold the image with the average hue value
    hsvImg.create(frame.size(), CvType.CV_8U);
    Imgproc.cvtColor(frame, hsvImg, Imgproc.COLOR_BGR2HSV);
    Core.split(hsvImg, hsvPlanes);

    // get the average hue value of the image
    double threshValue = getHistAverage(hsvImg, hsvPlanes.get(0));

    Imgproc.threshold(hsvPlanes.get(0), thresholdImg, threshValue, 179.0, thresh_type);

    Imgproc.blur(thresholdImg, thresholdImg, new Size(5, 5));

    // dilate to fill gaps, erode to smooth edges
    Imgproc.dilate(thresholdImg, thresholdImg, new Mat(), new Point(-1, -1), 1);
    Imgproc.erode(thresholdImg, thresholdImg, new Mat(), new Point(-1, -1), 3);

    Imgproc.threshold(thresholdImg, thresholdImg, threshValue, 179.0, Imgproc.THRESH_BINARY);

    // create the new image
    Mat foreground = new Mat(frame.size(), CvType.CV_8UC3, new Scalar(255, 255, 255));
    frame.copyTo(foreground, thresholdImg);

    return foreground;
}
 
开发者ID:Evegen55,项目名称:main_carauto_board,代码行数:41,代码来源:MagicTabController.java

示例11: main

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public static void main(String args[]) {
   System.loadLibrary(Core.NATIVE_LIBRARY_NAME); // Import openCV
   Webcam panel = new Webcam(); // Initialize itself

   // Initialize JPanel
   JFrame frame = new JFrame("Webcam");
   frame.setSize(200, 200);
   frame.setContentPane(panel);
   frame.setVisible(true);

   VideoCapture camera = new VideoCapture(0); // The camera

   // Attempt to set the frame size, but it doesn't really work. Only just makes it bigger
   camera.set(Videoio.CAP_PROP_FRAME_WIDTH, 1900);
   camera.set(Videoio.CAP_PROP_FRAME_HEIGHT, 1000);


   // Special window listener because there are threads that need to be shutdown on a close
   frame.addWindowListener(new WindowAdapter() {
      @Override
      public void windowClosing(WindowEvent e) {
         e.getWindow().dispose();
         camera.release();
         System.exit(0);
      }
   });

   if (camera.isOpened()) {

      // Create SwingWorker to encapsulate the process in a thread
      SwingWorker<Void, Mat> worker = new SwingWorker<Void, Mat>() {
         @Override
         protected Void doInBackground() throws Exception {

            // Put something into thisFrame so it doesn't glitch at the beginning
            Mat thisFrame = new Mat();
            camera.read(thisFrame);
            Imgproc.cvtColor(thisFrame, thisFrame, Imgproc.COLOR_BGR2GRAY); // Convert the diff to gray

            // Set up new Mats for diffing them later, manually set the amount of channels to avoid an openCV error
            Mat pastFrame = new Mat();
            Mat diff = new Mat();


            // isCancelled is set by the SwingWorker
            while (!isCancelled()) {

               thisFrame.copyTo(pastFrame); // What was previously the frame is now the pastFrame
               camera.read(thisFrame); // Get camera image, and set it to currentImage
               Imgproc.cvtColor(thisFrame, thisFrame, Imgproc.COLOR_BGR2GRAY); // Convert the diff to gray

               if (!thisFrame.empty()) {

                  // Set the frame size to have a nice border around the image
                  frame.setSize(thisFrame.width() + 40, thisFrame.height() + 60);


                  Core.absdiff(thisFrame, pastFrame, diff); // Diff the frames
                  Imgproc.GaussianBlur(diff, diff, new Size(7, 7), 7); // Despeckle
                  Imgproc.threshold(diff, diff, 5, 255, 1); // Threshhold the gray

                  image = matrixToBuffer(getFace(thisFrame, diff)); // Update the display image
                  panel.repaint(); // Refresh the panel
               } else {
                  System.err.println("Error: no frame captured");
               }
               //Thread.sleep(70); // Set refresh rate, as well as prevent the code from tripping over itself
            }
            return null;
         }
      };
      worker.execute();
   }
   return;
}
 
开发者ID:grantslatton,项目名称:GarfieldLanguage,代码行数:76,代码来源:Webcam.java

示例12: process

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
@Override
public void process(Mat input, Mat mask) {
    channels = new ArrayList<>();

    switch(color){
        case RED:
            if(threshold == -1){
                threshold = 164;
            }

            Imgproc.cvtColor(input, input, Imgproc.COLOR_RGB2Lab);
            Imgproc.GaussianBlur(input,input,new Size(3,3),0);
            Core.split(input, channels);
            Imgproc.threshold(channels.get(1), mask, threshold, 255, Imgproc.THRESH_BINARY);
            break;
        case BLUE:
            if(threshold == -1){
                threshold = 145;
            }

            Imgproc.cvtColor(input, input, Imgproc.COLOR_RGB2YUV);
            Imgproc.GaussianBlur(input,input,new Size(3,3),0);
            Core.split(input, channels);
            Imgproc.threshold(channels.get(1), mask, threshold, 255, Imgproc.THRESH_BINARY);
            break;
        case YELLOW:
            if(threshold == -1){
                threshold = 95;
            }

            Imgproc.cvtColor(input, input, Imgproc.COLOR_RGB2YUV);
            Imgproc.GaussianBlur(input,input,new Size(3,3),0);
            Core.split(input, channels);
            Imgproc.threshold(channels.get(1), mask, threshold, 255, Imgproc.THRESH_BINARY_INV);
            break;
    }

    for(int i=0;i<channels.size();i++){
        channels.get(i).release();
    }

    input.release();

}
 
开发者ID:GTHSRobotics,项目名称:DogeCV,代码行数:45,代码来源:LeviColorFilter.java

示例13: computeModel

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public void computeModel(ArrayList<MetaData> photos)
{
	numPhotos = photos.size();
	model.setNumPhotos(numPhotos);

	MatOfKeyPoint[] keypoints = new MatOfKeyPoint[numPhotos];
	Mat[] descriptors = new Mat[numPhotos];
	Mat allDescriptors = new Mat();
	ArrayList<Integer> descriptorLabels = new ArrayList<Integer>();

	// compute keypoints and descriptors
	Mat currentImg = null;
	for (int a = 0; a < numPhotos; a++)
	{
		// System.out.println("now:" + animalFiles.get(a));
		currentImg = Highgui.imread(photos.get(a).getZooName().toString(), 0);
		Imgproc.resize(currentImg, currentImg, new Size(150, 250));
		Imgproc.equalizeHist(currentImg, currentImg);
		Imgproc.threshold(currentImg, currentImg, 127, 255, Imgproc.THRESH_BINARY);

		featureDetector.detect(currentImg, keypoints[a]);
		descriptorExtractor.compute(currentImg, keypoints[a], descriptors[a]);

		allDescriptors.push_back(descriptors[a]);

		for (int i = 0; i < descriptors[a].rows(); i++)
			descriptorLabels.add(a);
	}
	System.out.println("label size:" + descriptorLabels.size());

	Mat clusterLabels = new Mat();
	Mat centers = new Mat();

	// set up all desriptors, init criteria
	allDescriptors.convertTo(allDescriptors, CvType.CV_32F);
	TermCriteria criteria = new TermCriteria(TermCriteria.EPS + TermCriteria.MAX_ITER, 100, 0.1);
	long before = System.currentTimeMillis();
	
	// compute clusters
	System.out.print("creating kmeans clusters...");
	Core.kmeans(allDescriptors, k, clusterLabels, criteria, 10, Core.KMEANS_PP_CENTERS, centers);
	System.out.println("done.");

	// map k-means centroid labels to descriptors of all images
	ArrayList<ArrayList<Integer>> clusterImageMap = new ArrayList<ArrayList<Integer>>();
	for (int nk = 0; nk < k + 1; nk++)
		clusterImageMap.add(new ArrayList<Integer>());
	for (int r = 0; r < clusterLabels.rows(); r++)
		clusterImageMap.get((int) clusterLabels.get(r, 0)[0]).add(descriptorLabels.get(r));

	model.setCentroids(centers);
	model.setLabels(clusterLabels);
	model.setClusterImageMap(clusterImageMap);
	model.setKeypoints(keypoints);
	model.setDescriptors(descriptors);

}
 
开发者ID:fossasia,项目名称:zooracle,代码行数:58,代码来源:KMeansMatcher.java

示例14: normalThresholding

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public static Mat normalThresholding(Mat img){
    Mat im = new Mat();
    Imgproc.threshold(img,im,120,255,Imgproc.THRESH_TRUNC);
    Imgproc.threshold(im,img,0,255,Imgproc.THRESH_OTSU+Imgproc.THRESH_BINARY);
    return img;
}
 
开发者ID:Sanahm,项目名称:SudoCAM-Ku,代码行数:7,代码来源:Thresholding.java

示例15: onActivityResult

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
    //Put it there, just in case:)
    super.onActivityResult(requestCode, resultCode, imageReturnedIntent);

    switch(requestCode) {
        case SELECT_PHOTO:
            if(resultCode == RESULT_OK && read_external_storage_granted){
                try {
                    final Uri imageUri = imageReturnedIntent.getData();
                    final InputStream imageStream = getContentResolver().openInputStream(imageUri);
                    final Bitmap selectedImage = BitmapFactory.decodeStream(imageStream);
                    src = new Mat(selectedImage.getHeight(), selectedImage.getWidth(), CvType.CV_8UC4);
                    Utils.bitmapToMat(selectedImage, src);
                    src_gray = new Mat(selectedImage.getHeight(), selectedImage.getWidth(), CvType.CV_8UC1);
                    switch (ACTION_MODE) {
                        case HomeActivity.GAUSSIAN_BLUR:
                            Imgproc.GaussianBlur(src, src, new Size(9, 9), 0);
                            break;
                        case HomeActivity.MEAN_BLUR:
                            Imgproc.blur(src, src, new Size(9, 9));
                            break;
                        case HomeActivity.MEDIAN_BLUR:
                            Imgproc.medianBlur(src, src, 9);
                            break;
                        case HomeActivity.SHARPEN:
                            Mat kernel = new Mat(3, 3, CvType.CV_16SC1);
                            //int[] values = {0, -1, 0, -1, 5, -1, 0, -1, 0};
                            Log.d("imageType", CvType.typeToString(src.type()) + "");
                            kernel.put(0, 0, 0, -1, 0, -1, 5, -1, 0, -1, 0);
                            Imgproc.filter2D(src, src, src_gray.depth(), kernel);
                            break;
                        case HomeActivity.DILATE:
                            Imgproc.cvtColor(src, src_gray, Imgproc.COLOR_BGR2GRAY);
                            Imgproc.threshold(src_gray, src_gray, 100, 255, Imgproc.THRESH_BINARY);
                            Mat kernelDilate = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(3, 3));
                            Imgproc.dilate(src_gray, src_gray, kernelDilate);
                            Imgproc.cvtColor(src_gray, src, Imgproc.COLOR_GRAY2RGBA, 4);
                            break;
                        case HomeActivity.ERODE:
                            Imgproc.cvtColor(src, src_gray, Imgproc.COLOR_BGR2GRAY);
                            Imgproc.threshold(src_gray, src_gray, 100, 255, Imgproc.THRESH_BINARY);
                            Mat kernelErode = Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, new Size(5, 5));
                            Imgproc.erode(src_gray, src_gray, kernelErode);
                            Imgproc.cvtColor(src_gray, src, Imgproc.COLOR_GRAY2RGBA, 4);
                            break;
                        case HomeActivity.THRESHOLD:
                            Imgproc.cvtColor(src, src_gray, Imgproc.COLOR_BGR2GRAY);
                            Imgproc.threshold(src_gray, src_gray, 100, 255, Imgproc.THRESH_BINARY);
                            Imgproc.cvtColor(src_gray, src, Imgproc.COLOR_GRAY2RGBA, 4);
                            break;
                        case HomeActivity.ADAPTIVE_THRESHOLD:
                            Imgproc.cvtColor(src, src_gray, Imgproc.COLOR_BGR2GRAY);
                            Imgproc.adaptiveThreshold(src_gray, src_gray, 255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C, Imgproc.THRESH_BINARY, 3, 0);
                            Imgproc.cvtColor(src_gray, src, Imgproc.COLOR_GRAY2RGBA, 4);
                            break;
                    }
                    Bitmap processedImage = Bitmap.createBitmap(src.cols(), src.rows(), Bitmap.Config.ARGB_8888);
                    Log.i("imageType", CvType.typeToString(src.type()) + "");
                    Utils.matToBitmap(src, processedImage);
                    ivImage.setImageBitmap(selectedImage);
                    ivImageProcessed.setImageBitmap(processedImage);
                    Log.i("process", "process done");
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                }
            }
            break;
    }
}
 
开发者ID:johnhany,项目名称:MOAAP,代码行数:71,代码来源:MainActivity.java


注:本文中的org.opencv.imgproc.Imgproc.threshold方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。