Java Code Examples for org.opencv.imgcodecs.Imgcodecs

The following examples show how to use org.opencv.imgcodecs.Imgcodecs. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: LPR   Source File: Utils.java    License: 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 2
@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 Project: AndroidDocumentScanner   Source File: Utils.java    License: 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 4
Source Project: pasm-yolov3-Android   Source File: Utils.java    License: 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 5
Source Project: OpenCV-Android-Object-Detection   Source File: Utils.java    License: 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 6
Source Project: SikuliX1   Source File: Element.java    License: 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 7
Source Project: SikuliX1   Source File: SXOpenCV.java    License: MIT License 6 votes vote down vote up
private static BufferedImage makeBufferedImage(Mat content, String type) {
  if (content.empty()) {
    return null;
  }
  BufferedImage bImg = null;
  MatOfByte bytemat = new MatOfByte();
  Imgcodecs.imencode(type, content, bytemat);
  byte[] bytes = bytemat.toArray();
  InputStream in = new ByteArrayInputStream(bytes);
  try {
    bImg = ImageIO.read(in);
  } catch (IOException ex) {
    Debug.log(-1, "SXOpenCV: makeBufferedImage: %s error(%s)", content, ex.getMessage());
  }
  return bImg;
}
 
Example 8
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.getHUD().clear();
        mMainActivity.invalidateHUD();
        mMainActivity.saveDocument(doc);
        doc.release();
        picture.release();

        mMainActivity.setImageProcessorBusy(false);
        mMainActivity.setAttemptToFocus(false);
        mMainActivity.waitSpinnerInvisible();

    }
 
Example 9
Source Project: react-native-documentscanner-android   Source File: Utils.java    License: 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
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 Project: OpenCV-android   Source File: Utils.java    License: 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 12
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 13
Source Project: opencv-documentscanner-android   Source File: Utils.java    License: 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 14
Source Project: Java-for-Data-Science   Source File: DetectFaceDemo.java    License: 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 Project: Java-for-Data-Science   Source File: OpenCVNonMavenExamples.java    License: 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 16
Source Project: Java-for-Data-Science   Source File: OpenCVNonMavenExamples.java    License: 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 17
Source Project: opencv-object-detection   Source File: TemplateMatching.java    License: 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 18
Source Project: OptimizedImageEnhance   Source File: GuidedFilterFlashExample.java    License: 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 19
Source Project: Document-Scanner   Source File: Utils.java    License: 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 20
Source Project: OptimizedImageEnhance   Source File: GuidedFilterEnhanceExample.java    License: 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 21
Source Project: sudokufx   Source File: Utils.java    License: 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 22
Source Project: real_time_circle_detection_android   Source File: Utils.java    License: 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 23
Source Project: Form-N-Fun   Source File: Utils.java    License: 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 24
Source Project: opentest   Source File: ImageFinder.java    License: 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 25
Source Project: SimpleDocumentScanner-Android   Source File: Utils.java    License: 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 Project: FtcSamples   Source File: Utils.java    License: 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 27
Source Project: javautils   Source File: HighGuiUtil.java    License: 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 28
Source Project: Human-hair-detection   Source File: OpenCVoperation.java    License: 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 29
Source Project: classchecks   Source File: CSVFileUtils.java    License: 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 30
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();
    }