org.opencv.imgcodecs.Imgcodecs Java Examples

The following examples show how to use org.opencv.imgcodecs.Imgcodecs. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CSVFileUtils.java    From classchecks with Apache License 2.0 6 votes vote down vote up
public static void loadImage(String saveRoute, List<Mat> matLists, List<Integer> labels, Integer faceLabel) {
	File saveRoot = new File(saveRoute);
	if(!saveRoot.exists()) {
		LOG.info("图片保存路径--" + saveRoute + "--不存在");
		return;
	}
	if(!saveRoot.isDirectory()) {
		LOG.info("图片路径--" + saveRoute+ "--不是一个文件夹");
		return;
	}
	
	File[] procImages = saveRoot.listFiles(new ImageFileFilter());
	for(int i = 0; i < procImages.length; i ++) {
		LOG.info("加载图片:" + procImages[i].getAbsolutePath());
		Mat m = Imgcodecs.imread(procImages[i].getAbsolutePath(), Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE);
		matLists.add(m);
		labels.add(faceLabel);
	}
}
 
Example #2
Source File: FaceRecognitionAppActivity.java    From FaceRecognitionApp with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("ResultOfMethodCallIgnored")
public void SaveImage(Mat mat) {
    Mat mIntermediateMat = new Mat();

    if (mat.channels() == 1) // Grayscale image
        Imgproc.cvtColor(mat, mIntermediateMat, Imgproc.COLOR_GRAY2BGR);
    else
        Imgproc.cvtColor(mat, mIntermediateMat, Imgproc.COLOR_RGBA2BGR);

    File path = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), TAG); // Save pictures in Pictures directory
    path.mkdir(); // Create directory if needed
    String fileName = "IMG_" + new SimpleDateFormat("yyyyMMdd_HHmmss_SSS", Locale.US).format(new Date()) + ".png";
    File file = new File(path, fileName);

    boolean bool = Imgcodecs.imwrite(file.toString(), mIntermediateMat);

    if (bool)
        Log.i(TAG, "SUCCESS writing image to external storage");
    else
        Log.e(TAG, "Failed writing image to external storage");
}
 
Example #3
Source File: Utils.java    From LPR with Apache License 2.0 6 votes vote down vote up
public static Mat loadResource(Context context, int resourceId, int flags) throws IOException
{
    InputStream is = context.getResources().openRawResource(resourceId);
    ByteArrayOutputStream os = new ByteArrayOutputStream(is.available());

    byte[] buffer = new byte[4096];
    int bytesRead;
    while ((bytesRead = is.read(buffer)) != -1) {
        os.write(buffer, 0, bytesRead);
    }
    is.close();

    Mat encoded = new Mat(1, os.size(), CvType.CV_8U);
    encoded.put(0, 0, os.toByteArray());
    os.close();

    Mat decoded = Imgcodecs.imdecode(encoded, flags);
    encoded.release();

    return decoded;
}
 
Example #4
Source File: Utils.java    From AndroidDocumentScanner with MIT License 6 votes vote down vote up
public static Mat loadResource(Context context, int resourceId, int flags) throws IOException
{
    InputStream is = context.getResources().openRawResource(resourceId);
    ByteArrayOutputStream os = new ByteArrayOutputStream(is.available());

    byte[] buffer = new byte[4096];
    int bytesRead;
    while ((bytesRead = is.read(buffer)) != -1) {
        os.write(buffer, 0, bytesRead);
    }
    is.close();

    Mat encoded = new Mat(1, os.size(), CvType.CV_8U);
    encoded.put(0, 0, os.toByteArray());
    os.close();

    Mat decoded = Imgcodecs.imdecode(encoded, flags);
    encoded.release();

    return decoded;
}
 
Example #5
Source File: Element.java    From SikuliNG with MIT License 6 votes vote down vote up
public static BufferedImage getBufferedImage(Mat mat, String type) {
  BufferedImage bImg = null;
  MatOfByte bytemat = new MatOfByte();
  if (SX.isNull(mat)) {
    mat = getNewMat();
  }
  Imgcodecs.imencode(type, mat, bytemat);
  byte[] bytes = bytemat.toArray();
  InputStream in = new ByteArrayInputStream(bytes);
  try {
    bImg = ImageIO.read(in);
  } catch (IOException ex) {
    log.error("getBufferedImage: %s error(%s)", mat, ex.getMessage());
  }
  return bImg;
}
 
Example #6
Source File: Utils.java    From MOAAP with MIT License 6 votes vote down vote up
public static Mat loadResource(Context context, int resourceId, int flags) throws IOException
{
    InputStream is = context.getResources().openRawResource(resourceId);
    ByteArrayOutputStream os = new ByteArrayOutputStream(is.available());

    byte[] buffer = new byte[4096];
    int bytesRead;
    while ((bytesRead = is.read(buffer)) != -1) {
        os.write(buffer, 0, bytesRead);
    }
    is.close();

    Mat encoded = new Mat(1, os.size(), CvType.CV_8U);
    encoded.put(0, 0, os.toByteArray());
    os.close();

    Mat decoded = Imgcodecs.imdecode(encoded, flags);
    encoded.release();

    return decoded;
}
 
Example #7
Source File: Utils.java    From MOAAP with MIT License 6 votes vote down vote up
public static Mat loadResource(Context context, int resourceId, int flags) throws IOException
{
    InputStream is = context.getResources().openRawResource(resourceId);
    ByteArrayOutputStream os = new ByteArrayOutputStream(is.available());

    byte[] buffer = new byte[4096];
    int bytesRead;
    while ((bytesRead = is.read(buffer)) != -1) {
        os.write(buffer, 0, bytesRead);
    }
    is.close();

    Mat encoded = new Mat(1, os.size(), CvType.CV_8U);
    encoded.put(0, 0, os.toByteArray());
    os.close();

    Mat decoded = Imgcodecs.imdecode(encoded, flags);
    encoded.release();

    return decoded;
}
 
Example #8
Source File: Element.java    From SikuliX1 with MIT License 6 votes vote down vote up
private static Mat getMatFromURL(URL url, boolean isMaskImage) {
  byte[] bytes = null;
  Mat content = new Mat();
  try {
    InputStream inputStream = url.openStream();
    bytes = inputStream.readAllBytes();
  } catch (IOException e) {
  }
  if (bytes != null) {
    MatOfByte matOfByte = new MatOfByte();
    matOfByte.fromArray(bytes);
    content = Imgcodecs.imdecode(matOfByte, -1);
    if (isMaskImage) {
      List<Mat> mats = SXOpenCV.extractMask(content, false);
      content = mats.get(1);
    }
  }
  return content;
}
 
Example #9
Source File: Utils.java    From OpenCV-AndroidSamples with MIT License 6 votes vote down vote up
public static Mat loadResource(Context context, int resourceId, int flags) throws IOException
{
    InputStream is = context.getResources().openRawResource(resourceId);
    ByteArrayOutputStream os = new ByteArrayOutputStream(is.available());

    byte[] buffer = new byte[4096];
    int bytesRead;
    while ((bytesRead = is.read(buffer)) != -1) {
        os.write(buffer, 0, bytesRead);
    }
    is.close();

    Mat encoded = new Mat(1, os.size(), CvType.CV_8U);
    encoded.put(0, 0, os.toByteArray());
    os.close();

    Mat decoded = Imgcodecs.imdecode(encoded, flags);
    encoded.release();

    return decoded;
}
 
Example #10
Source File: Utils.java    From OpenCV-Android-Object-Detection with MIT License 6 votes vote down vote up
public static Mat loadResource(Context context, int resourceId, int flags) throws IOException
{
    InputStream is = context.getResources().openRawResource(resourceId);
    ByteArrayOutputStream os = new ByteArrayOutputStream(is.available());

    byte[] buffer = new byte[4096];
    int bytesRead;
    while ((bytesRead = is.read(buffer)) != -1) {
        os.write(buffer, 0, bytesRead);
    }
    is.close();

    Mat encoded = new Mat(1, os.size(), CvType.CV_8U);
    encoded.put(0, 0, os.toByteArray());
    os.close();

    Mat decoded = Imgcodecs.imdecode(encoded, flags);
    encoded.release();

    return decoded;
}
 
Example #11
Source File: CSVFileUtils.java    From classchecks with Apache License 2.0 6 votes vote down vote up
/**
 * 读取CSV文件
 * @param filePath 文件的绝对路径
 * @param matLists
 * @param labels
 */
public static void CSVRead(String filePath, List<Mat> matLists, List<Integer> labels) {
	try {
		File file = new File(filePath);
		BufferedReader br = new BufferedReader(new FileReader(file));
		String line = null;
		while((line = br.readLine()) != null) {
			String [] tmp = line.split(";");
			if(!tmp[0].isEmpty() && !tmp[1].isEmpty()) {
				matLists.add(Imgcodecs.imread(tmp[0], Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE));
				labels.add(Integer.valueOf(tmp[1]));
			}
		}
		br.close();
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example #12
Source File: CSVFileUtils.java    From classchecks with Apache License 2.0 6 votes vote down vote up
public static void loadImage(String saveRoute, List<Mat> matLists) {
	File saveRoot = new File(saveRoute);
	if(!saveRoot.exists()) {
		LOG.info("图片保存路径--" + saveRoute + "--不存在");
		return;
	}
	if(!saveRoot.isDirectory()) {
		LOG.info("图片路径--" + saveRoute+ "--不是一个文件夹");
		return;
	}
	File[] procImages = saveRoot.listFiles(new ImageFileFilter());
	for(int i = 0; i < procImages.length; i ++) {
		//LOG.info("加载图片:" + procImages[i].getAbsolutePath());
		Mat m = Imgcodecs.imread(procImages[i].getAbsolutePath(), Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE);
		matLists.add(m);
	}
}
 
Example #13
Source File: Utils.java    From Chinese-number-gestures-recognition with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static Mat loadResource(Context context, int resourceId, int flags) throws IOException
{
    InputStream is = context.getResources().openRawResource(resourceId);
    ByteArrayOutputStream os = new ByteArrayOutputStream(is.available());

    byte[] buffer = new byte[4096];
    int bytesRead;
    while ((bytesRead = is.read(buffer)) != -1) {
        os.write(buffer, 0, bytesRead);
    }
    is.close();

    Mat encoded = new Mat(1, os.size(), CvType.CV_8U);
    encoded.put(0, 0, os.toByteArray());
    os.close();

    Mat decoded = Imgcodecs.imdecode(encoded, flags);
    encoded.release();

    return decoded;
}
 
Example #14
Source File: DetectFaceDemo.java    From Java-for-Data-Science with MIT License 6 votes vote down vote up
public void run() {
  System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
  String base = "C:/Books in Progress/Java for Data Science/Chapter 10/OpenCVExamples/src/resources";
  CascadeClassifier faceDetector = 
          new CascadeClassifier(base + "/lbpcascade_frontalface.xml");
  
  Mat image = Imgcodecs.imread(base + "/images.jpg");

  MatOfRect faceVectors = new MatOfRect();
  faceDetector.detectMultiScale(image, faceVectors);

  out.println(faceVectors.toArray().length + " faces found");

  for (Rect rect : faceVectors.toArray()) {
      Imgproc.rectangle(image, new Point(rect.x, rect.y), 
              new Point(rect.x + rect.width, rect.y + rect.height), 
              new Scalar(0, 255, 0));
  }
  Imgcodecs.imwrite("faceDetection.png", image);
}
 
Example #15
Source File: ImageProcessor.java    From Document-Scanner with GNU General Public License v3.0 6 votes vote down vote up
public void processPicture( Mat picture ) {

        Mat img = Imgcodecs.imdecode(picture, Imgcodecs.CV_LOAD_IMAGE_UNCHANGED);
        picture.release();

        Log.d(TAG, "processPicture - imported image " + img.size().width + "x" + img.size().height);

        if (mBugRotate) {
            Core.flip(img, img, 1 );
            Core.flip(img, img, 0 );
        }

        ScannedDocument doc = detectDocument(img);
        mMainActivity.saveDocument(doc);

        doc.release();
        picture.release();

        mMainActivity.setImageProcessorBusy(false);
        mMainActivity.waitSpinnerInvisible();
    }
 
Example #16
Source File: Utils.java    From opencv-documentscanner-android with Apache License 2.0 6 votes vote down vote up
public static Mat loadResource(Context context, int resourceId, int flags) throws IOException
{
    InputStream is = context.getResources().openRawResource(resourceId);
    ByteArrayOutputStream os = new ByteArrayOutputStream(is.available());

    byte[] buffer = new byte[4096];
    int bytesRead;
    while ((bytesRead = is.read(buffer)) != -1) {
        os.write(buffer, 0, bytesRead);
    }
    is.close();

    Mat encoded = new Mat(1, os.size(), CvType.CV_8U);
    encoded.put(0, 0, os.toByteArray());
    os.close();

    Mat decoded = Imgcodecs.imdecode(encoded, flags);
    encoded.release();

    return decoded;
}
 
Example #17
Source File: OpenCVNonMavenExamples.java    From Java-for-Data-Science with MIT License 6 votes vote down vote up
public void sharpenImage() {
        String fileName = "SharpnessExample2.png";
        fileName = "smoothCat.jpg";
        fileName = "blurredText.jpg";
        fileName = "Blurred Text3.jpg";
        try {
//            Not working that well !!!
            Mat source = Imgcodecs.imread(fileName,
                    //                    Imgcodecs.CV_LOAD_IMAGE_COLOR);
                    Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE);
            Mat destination = new Mat(source.rows(), source.cols(), source.type());
            Imgproc.GaussianBlur(source, destination, new Size(0, 0), 10);
            // The following was used witht he cat
//            Core.addWeighted(source, 1.5, destination, -0.75, 0, destination);
//            Core.addWeighted(source, 2.5, destination, -1.5, 0, destination);
            Core.addWeighted(source, 1.5, destination, -0.75, 0, destination);
            Imgcodecs.imwrite("sharpenedCat.jpg", destination);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
 
Example #18
Source File: OpenCVoperation.java    From Human-hair-detection with Apache License 2.0 6 votes vote down vote up
public void skinSegmentation()
{
    matrix3_skindetection = new Mat(matrix2_grabcut.size(),matrix2_grabcut.type()); 
    matrix3_skindetection.setTo(new Scalar(0,0,255));
    Mat skinMask = new Mat();
    Mat hsvMatrix = new Mat();
    
    Scalar lower = new Scalar(0,48,80);
    Scalar upper = new Scalar(20,255,255);
    
    Imgproc.cvtColor(matrix2_grabcut, hsvMatrix, Imgproc.COLOR_BGR2HSV);
    Core.inRange(hsvMatrix, lower, upper, skinMask);
    
    Mat kernel =Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE,new Size(11,11));
    Imgproc.erode(skinMask, skinMask, kernel);
    Imgproc.dilate(skinMask, skinMask, kernel);  
    
    Imgproc.GaussianBlur(skinMask,skinMask, new Size(3,3), 0);
    
    Core.bitwise_and(matrix2_grabcut, matrix2_grabcut, matrix3_skindetection,skinMask);
    Imgcodecs.imwrite(resultDirectory+skinDetectionOutput , matrix3_skindetection);
}
 
Example #19
Source File: OpenCVNonMavenExamples.java    From Java-for-Data-Science with MIT License 6 votes vote down vote up
public static void denoise() {
        String imgInPath = "captchaExample.jpg";
        imgInPath = "MyCaptcha.PNG";
        imgInPath = "blurredtext.jpg";
        String imgOutPath = "captchaNoiseRemovedExample.png";
        imgOutPath = "MyNoiseRemovedCaptcha.PNG";

        Mat image = Imgcodecs.imread(imgInPath);
        Mat out = new Mat();
        Mat tmp = new Mat();
        Mat kernel = new Mat(new Size(3, 3), CvType.CV_8UC1, new Scalar(255));
//        Mat kernel = new Mat(image.size(), CvType.CV_8UC1, new Scalar(255));
        Imgproc.morphologyEx(image, tmp, Imgproc.MORPH_OPEN, kernel);
        Imgproc.morphologyEx(tmp, out, Imgproc.MORPH_CLOSE, kernel);
        Imgcodecs.imwrite(imgOutPath, out);
    }
 
Example #20
Source File: TemplateMatching.java    From opencv-object-detection with MIT License 6 votes vote down vote up
public static void main(String[] args) {
	
	System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
	Mat source=null;
	Mat template=null;
	String filePath="Sample Image\\";
	source=Imgcodecs.imread(filePath+"kapadokya.jpg");
	template=Imgcodecs.imread(filePath+"balon.jpg");

	Mat outputImage=new Mat();	
	int machMethod=Imgproc.TM_CCOEFF;
  
       Imgproc.matchTemplate(source, template, outputImage, machMethod);

   
       MinMaxLocResult mmr = Core.minMaxLoc(outputImage);
       Point matchLoc=mmr.maxLoc;

       Imgproc.rectangle(source, matchLoc, new Point(matchLoc.x + template.cols(),
               matchLoc.y + template.rows()), new Scalar(255, 255, 255));

       Imgcodecs.imwrite(filePath+"sonuc.jpg", source);
       System.out.println("��lem tamamland�.");
}
 
Example #21
Source File: HighGuiUtil.java    From javautils with Apache License 2.0 6 votes vote down vote up
/**
 * Detects faces in an image, draws boxes around them, and writes the results
 * @param fileName
 * @param destName
 */
public static void drawRect(String fileName, String destName){
    Mat image = Imgcodecs.imread(fileName);
    // Create a face detector from the cascade file in the resources
    // directory.
    CascadeClassifier faceDetector = new CascadeClassifier("libs/lbpcascade_frontalface.xml");
    // Detect faces in the image.
    // MatOfRect is a special container class for Rect.
    MatOfRect faceDetections = new MatOfRect();
    faceDetector.detectMultiScale(image, faceDetections);
    // Draw a bounding box around each face.
    for (Rect rect : faceDetections.toArray()) {
        Core.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width,
                rect.y + rect.height), new Scalar(0, 255, 0));
    }

    Imgcodecs.imwrite(destName, image);

}
 
Example #22
Source File: GuidedFilterFlashExample.java    From OptimizedImageEnhance with MIT License 6 votes vote down vote up
public static void main(String[] args) {
	String imgPath = "src/main/resources/dcp_images/flash/cave-flash.bmp";
	String guidedImgPath = "src/main/resources/dcp_images/flash/cave-noflash.bmp";
	Mat image = Imgcodecs.imread(imgPath, Imgcodecs.CV_LOAD_IMAGE_COLOR);
	new ImShow("image").showImage(image);
	image.convertTo(image, CvType.CV_32F);
	Mat guide = Imgcodecs.imread(guidedImgPath, Imgcodecs.CV_LOAD_IMAGE_COLOR);
	guide.convertTo(guide, CvType.CV_32F);
	List<Mat> img = new ArrayList<>();
	List<Mat> gid = new ArrayList<>();
	Core.split(image, img);
	Core.split(guide, gid);
	
	int r = 8;
	double eps = 0.02 * 0.02;
	Mat q_r = Filters.GuidedImageFilter(img.get(0), gid.get(0), r, eps);
	Mat q_g = Filters.GuidedImageFilter(img.get(1), gid.get(1), r, eps);
	Mat q_b = Filters.GuidedImageFilter(img.get(2), gid.get(2), r, eps);
	Mat q = new Mat();
	Core.merge(new ArrayList<>(Arrays.asList(q_r, q_g, q_b)), q);
	q.convertTo(q, CvType.CV_8UC1);
	new ImShow("q").showImage(q);
}
 
Example #23
Source File: Utils.java    From Document-Scanner with GNU General Public License v3.0 6 votes vote down vote up
public static Mat loadResource(Context context, int resourceId, int flags) throws IOException
{
    InputStream is = context.getResources().openRawResource(resourceId);
    ByteArrayOutputStream os = new ByteArrayOutputStream(is.available());

    byte[] buffer = new byte[4096];
    int bytesRead;
    while ((bytesRead = is.read(buffer)) != -1) {
        os.write(buffer, 0, bytesRead);
    }
    is.close();

    Mat encoded = new Mat(1, os.size(), CvType.CV_8U);
    encoded.put(0, 0, os.toByteArray());
    os.close();

    Mat decoded = Imgcodecs.imdecode(encoded, flags);
    encoded.release();

    return decoded;
}
 
Example #24
Source File: Utils.java    From FtcSamples with MIT License 6 votes vote down vote up
public static Mat loadResource(Context context, int resourceId, int flags) throws IOException
{
    InputStream is = context.getResources().openRawResource(resourceId);
    ByteArrayOutputStream os = new ByteArrayOutputStream(is.available());

    byte[] buffer = new byte[4096];
    int bytesRead;
    while ((bytesRead = is.read(buffer)) != -1) {
        os.write(buffer, 0, bytesRead);
    }
    is.close();

    Mat encoded = new Mat(1, os.size(), CvType.CV_8U);
    encoded.put(0, 0, os.toByteArray());
    os.close();

    Mat decoded = Imgcodecs.imdecode(encoded, flags);
    encoded.release();

    return decoded;
}
 
Example #25
Source File: Utils.java    From SimpleDocumentScanner-Android with MIT License 6 votes vote down vote up
public static Mat loadResource(Context context, int resourceId, int flags) throws IOException
{
    InputStream is = context.getResources().openRawResource(resourceId);
    ByteArrayOutputStream os = new ByteArrayOutputStream(is.available());

    byte[] buffer = new byte[4096];
    int bytesRead;
    while ((bytesRead = is.read(buffer)) != -1) {
        os.write(buffer, 0, bytesRead);
    }
    is.close();

    Mat encoded = new Mat(1, os.size(), CvType.CV_8U);
    encoded.put(0, 0, os.toByteArray());
    os.close();

    Mat decoded = Imgcodecs.imdecode(encoded, flags);
    encoded.release();

    return decoded;
}
 
Example #26
Source File: ImageFinder.java    From opentest with MIT License 6 votes vote down vote up
/**
 * Finds a template image on the screen. Throws an exception when the image
 * wasn't found or the desired accuracy couldn't be met.
 *
 * @param sourceScreenRect The rectangle on the screen to look into.
 * @param templateImage The template image to find.
 * @param desiredAccuracy The desired accuracy of the find operation as a
 * number between 0 and 1.
 * @return An ImageFinderResult object that stores the rectangle of the
 * found image and desired accuracy.
 */
@Override
public ImageFinderResult findImage(Rectangle sourceScreenRect, File templateImage, double desiredAccuracy) {
    try {
        BufferedImage capture = new Robot().createScreenCapture(sourceScreenRect);
        Mat sourceMat = CvHelper.convertToMat(capture);
        Mat templateMat = Imgcodecs.imread(templateImage.getAbsolutePath());
        return this.findImage(sourceMat, templateMat, desiredAccuracy);
    } catch (Exception ex) {
        throw new RuntimeException(String.format(
                "An error ocurred while trying to find an image on screen at (%s, %s, %s, %s)",
                sourceScreenRect.x,
                sourceScreenRect.y,
                sourceScreenRect.width,
                sourceScreenRect.height), ex);
    }
}
 
Example #27
Source File: GuidedFilterEnhanceExample.java    From OptimizedImageEnhance with MIT License 6 votes vote down vote up
public static void main(String[] args) {
	String imgPath = "src/main/resources/dcp_images/enhancement/tulips.bmp";
	Mat image = Imgcodecs.imread(imgPath, Imgcodecs.CV_LOAD_IMAGE_COLOR);
	new ImShow("image").showImage(image);
	image.convertTo(image, CvType.CV_32F);
	List<Mat> img = new ArrayList<>();
	Core.split(image, img);
	int r = 16;
	double eps = 0.01;
	
	Mat q_r = Filters.GuidedImageFilter(img.get(0), img.get(0), r, eps);
	Mat q_g = Filters.GuidedImageFilter(img.get(1), img.get(1), r, eps);
	Mat q_b = Filters.GuidedImageFilter(img.get(2), img.get(2), r, eps);
	
	Mat q = new Mat();
	Core.merge(new ArrayList<>(Arrays.asList(q_r, q_g, q_b)), q);
	q.convertTo(q, CvType.CV_8UC1);
	new ImShow("q").showImage(q);
}
 
Example #28
Source File: Utils.java    From sudokufx with Apache License 2.0 6 votes vote down vote up
public static Mat loadResource(Context context, int resourceId, int flags) throws IOException
{
    InputStream is = context.getResources().openRawResource(resourceId);
    ByteArrayOutputStream os = new ByteArrayOutputStream(is.available());

    byte[] buffer = new byte[4096];
    int bytesRead;
    while ((bytesRead = is.read(buffer)) != -1) {
        os.write(buffer, 0, bytesRead);
    }
    is.close();

    Mat encoded = new Mat(1, os.size(), CvType.CV_8U);
    encoded.put(0, 0, os.toByteArray());
    os.close();

    Mat decoded = Imgcodecs.imdecode(encoded, flags);
    encoded.release();

    return decoded;
}
 
Example #29
Source File: Utils.java    From real_time_circle_detection_android with MIT License 6 votes vote down vote up
public static Mat loadResource(Context context, int resourceId, int flags) throws IOException
{
    InputStream is = context.getResources().openRawResource(resourceId);
    ByteArrayOutputStream os = new ByteArrayOutputStream(is.available());

    byte[] buffer = new byte[4096];
    int bytesRead;
    while ((bytesRead = is.read(buffer)) != -1) {
        os.write(buffer, 0, bytesRead);
    }
    is.close();

    Mat encoded = new Mat(1, os.size(), CvType.CV_8U);
    encoded.put(0, 0, os.toByteArray());
    os.close();

    Mat decoded = Imgcodecs.imdecode(encoded, flags);
    encoded.release();

    return decoded;
}
 
Example #30
Source File: Utils.java    From Form-N-Fun with MIT License 6 votes vote down vote up
public static Mat loadResource(Context context, int resourceId, int flags) throws IOException
{
    InputStream is = context.getResources().openRawResource(resourceId);
    ByteArrayOutputStream os = new ByteArrayOutputStream(is.available());

    byte[] buffer = new byte[4096];
    int bytesRead;
    while ((bytesRead = is.read(buffer)) != -1) {
        os.write(buffer, 0, bytesRead);
    }
    is.close();

    Mat encoded = new Mat(1, os.size(), CvType.CV_8U);
    encoded.put(0, 0, os.toByteArray());
    os.close();

    Mat decoded = Imgcodecs.imdecode(encoded, flags);
    encoded.release();

    return decoded;
}