本文整理汇总了Java中org.opencv.imgproc.Imgproc.adaptiveThreshold方法的典型用法代码示例。如果您正苦于以下问题:Java Imgproc.adaptiveThreshold方法的具体用法?Java Imgproc.adaptiveThreshold怎么用?Java Imgproc.adaptiveThreshold使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.opencv.imgproc.Imgproc
的用法示例。
在下文中一共展示了Imgproc.adaptiveThreshold方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: FindMatch
import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
int FindMatch(Mat test_image) {
Imgproc.dilate(test_image, test_image,
Imgproc.getStructuringElement(Imgproc.CV_SHAPE_CROSS,
new Size(3,3)));
// Resize the image
Imgproc.resize(test_image, test_image, new Size(width, height));
// Convert the image to grayscale
// Imgproc.cvtColor(test_image, test_image, Imgproc.COLOR_RGB2GRAY);
// Adaptive Threshold
Imgproc.adaptiveThreshold(test_image, test_image, 255, Imgproc.ADAPTIVE_THRESH_MEAN_C,
Imgproc.THRESH_BINARY_INV, 15,2);
Mat test = new Mat(1, test_image.rows() *
test_image.cols(), CvType.CV_32FC1);
int count = 0;
for (int i = 0 ; i < test_image.rows(); i++) {
for (int j = 0; j < test_image.cols(); j++) {
test.put(0, count, test_image.get(i, j)[0]);
count++;
}
}
Mat results = new Mat(1, 1, CvType.CV_8U);
knn.find_nearest(test, 10, results, new Mat(), new Mat());
Log.i("Result:", "" + results.get(0,0)[0]);
return (int)(results.get(0,0)[0]);
}
示例2: setFilter
import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
private void setFilter() {
//Apply gaussian blur to remove noise
Imgproc.GaussianBlur(image, image, new Size(5, 5), 0);
//Threshold
Imgproc.adaptiveThreshold(image, image, 255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C, Imgproc.THRESH_BINARY, 7, 1);
//Invert the image
Core.bitwise_not(image, image);
//Dilate
Mat kernel = Imgproc.getStructuringElement(Imgproc.MORPH_DILATE, new Size(3, 3), new Point(1, 1));
Imgproc.dilate(image, image, kernel);
}
示例3: 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;
}
示例4: processarAlgoritmo
import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public void processarAlgoritmo(String diretorioImagem, String nomeDaImagem) {
Mat imagemOriginal = Imgcodecs.imread(diretorioImagem, Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE);
Mat imagemTratada = new Mat(imagemOriginal.rows(), imagemOriginal.cols(), imagemOriginal.type());
imagemTratada = imagemOriginal;
Imgproc.adaptiveThreshold(imagemOriginal, imagemTratada, 500, Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY, 11, 1);
Imgcodecs.imwrite(System.getProperty("user.home") + "/Desktop/" + nomeDaImagem + ".png", imagemTratada);
}
示例5: FindMatch
import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
int FindMatch(Mat test_image)
{
//Dilate the image
Imgproc.dilate(test_image, test_image, Imgproc.getStructuringElement(Imgproc.CV_SHAPE_CROSS, new Size(3,3)));
//Resize the image to match it with the sample image size
Imgproc.resize(test_image, test_image, new Size(width, height));
//Convert the image to grayscale
Imgproc.cvtColor(test_image, test_image, Imgproc.COLOR_RGB2GRAY);
//Adaptive Threshold
Imgproc.adaptiveThreshold(test_image,test_image,255,Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY_INV,15, 2);
Mat test = new Mat(1, test_image.rows() * test_image.cols(), CvType.CV_32FC1);
int count = 0;
for(int i = 0 ; i < test_image.rows(); i++)
{
for(int j = 0 ; j < test_image.cols(); j++) {
test.put(0, count, test_image.get(i, j)[0]);
count++;
}
}
Mat results = new Mat(1, 1, CvType.CV_8U);
//K-NN Prediction
//return (int)knn.findNearest(test, 10, results);
//SVM Prediction
return (int)svm.predict(test);
}
示例6: adaptativeThresholding
import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public static Mat adaptativeThresholding(Mat img){
Mat im = new Mat();
Imgproc.medianBlur(img,im,5);
Imgproc.adaptiveThreshold(im,img,255,Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C,Imgproc.THRESH_BINARY,21,2);
return img;
}
示例7: 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;
}
}