org.opencv.core.Core Java Examples

The following examples show how to use org.opencv.core.Core. 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: SimpleSampleTests.java    From super-cloudops with Apache License 2.0 7 votes vote down vote up
@Test
public void test1() {
	System.out.println("Welcome to OpenCV " + Core.VERSION);

	Mat m = new Mat(5, 10, CvType.CV_8UC1, new Scalar(0));
	System.out.println("OpenCV Mat: " + m);
	Mat mr1 = m.row(1);
	mr1.setTo(new Scalar(1));

	Mat mc5 = m.col(5);
	mc5.setTo(new Scalar(5));
	System.out.println("OpenCV Mat data:\n" + m.dump());
}
 
Example #2
Source File: FpsMeter.java    From faceswap with Apache License 2.0 6 votes vote down vote up
public void measure() {
    if (!mIsInitialized) {
        init();
        mIsInitialized = true;
    } else {
        mFramesCouner++;
        if (mFramesCouner % STEP == 0) {
            long time = Core.getTickCount();
            double fps = STEP * mFrequency / (time - mprevFrameTime);
            mprevFrameTime = time;
            if (mWidth != 0 && mHeight != 0)
                mStrfps = FPS_FORMAT.format(fps) + " FPS@" + Integer.valueOf(mWidth) + "x" + Integer.valueOf(mHeight);
            else
                mStrfps = FPS_FORMAT.format(fps) + " FPS";
            Log.i(TAG, mStrfps);
        }
    }
}
 
Example #3
Source File: RecognitionActivity.java    From Android-Face-Recognition-with-Deep-Learning-Test-Framework with Apache License 2.0 6 votes vote down vote up
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
    Mat imgRgba = inputFrame.rgba();
    Mat img = new Mat();
    imgRgba.copyTo(img);
    List<Mat> images = ppF.getProcessedImage(img, PreProcessorFactory.PreprocessingMode.RECOGNITION);
    Rect[] faces = ppF.getFacesForRecognition();

    // Selfie / Mirror mode
    if(front_camera){
        Core.flip(imgRgba,imgRgba,1);
    }
    if(images == null || images.size() == 0 || faces == null || faces.length == 0 || ! (images.size() == faces.length)){
        // skip
        return imgRgba;
    } else {
        faces = MatOperation.rotateFaces(imgRgba, faces, ppF.getAngleForRecognition());
        for(int i = 0; i<faces.length; i++){
            MatOperation.drawRectangleAndLabelOnPreview(imgRgba, faces[i], rec.recognize(images.get(i), ""), front_camera);
        }
        return imgRgba;
    }
}
 
Example #4
Source File: DetectionActivity.java    From Android-Face-Recognition-with-Deep-Learning-Test-Framework with Apache License 2.0 6 votes vote down vote up
@Override
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
    Mat imgRgba = inputFrame.rgba();
    Mat img = new Mat();
    imgRgba.copyTo(img);
    List<Mat> images = ppF.getCroppedImage(img);
    Rect[] faces = ppF.getFacesForRecognition();

    // Selfie / Mirror mode
    if(front_camera){
        Core.flip(imgRgba,imgRgba,1);
    }
    if(images == null || images.size() == 0 || faces == null || faces.length == 0 || ! (images.size() == faces.length)){
        // skip
        return imgRgba;
    } else {
        faces = MatOperation.rotateFaces(imgRgba, faces, ppF.getAngleForRecognition());
        for(int i = 0; i<faces.length; i++){
            MatOperation.drawRectangleAndLabelOnPreview(imgRgba, faces[i], "", front_camera);
        }
        return imgRgba;
    }
}
 
Example #5
Source File: FpsMeter.java    From FTCVision with MIT License 6 votes vote down vote up
public void measure() {
    if (!mIsInitialized) {
        init();
        mIsInitialized = true;
    } else {
        mFramesCouner++;
        if (mFramesCouner % STEP == 0) {
            long time = Core.getTickCount();
            double fps = STEP * mFrequency / (time - mprevFrameTime);
            mprevFrameTime = time;
            if (mWidth != 0 && mHeight != 0)
                mStrfps = FPS_FORMAT.format(fps) + " FPS@" + Integer.valueOf(mWidth) + "x" + Integer.valueOf(mHeight);
            else
                mStrfps = FPS_FORMAT.format(fps) + " FPS";
            Log.i(TAG, mStrfps);
        }
    }
}
 
Example #6
Source File: FpsMeter.java    From OpenCvFaceDetect with Apache License 2.0 6 votes vote down vote up
public void measure() {
    if (!mIsInitialized) {
        init();
        mIsInitialized = true;
    } else {
        mFramesCouner++;
        if (mFramesCouner % STEP == 0) {
            long time = Core.getTickCount();
            double fps = STEP * mFrequency / (time - mprevFrameTime);
            mprevFrameTime = time;
            if (mWidth != 0 && mHeight != 0)
                mStrfps = FPS_FORMAT.format(fps) + " FPS@" + Integer.valueOf(mWidth) + "x" + Integer.valueOf(mHeight);
            else
                mStrfps = FPS_FORMAT.format(fps) + " FPS";
            Log.i(TAG, mStrfps);
        }
    }
}
 
Example #7
Source File: ComparisonFrameRender.java    From OpenCV-AndroidSamples with MIT License 6 votes vote down vote up
@Override
public Mat render(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
    Mat undistortedFrame = new Mat(inputFrame.rgba().size(), inputFrame.rgba().type());
    Imgproc.undistort(inputFrame.rgba(), undistortedFrame,
            mCalibrator.getCameraMatrix(), mCalibrator.getDistortionCoefficients());

    Mat comparisonFrame = inputFrame.rgba();
    undistortedFrame.colRange(new Range(0, mWidth / 2)).copyTo(comparisonFrame.colRange(new Range(mWidth / 2, mWidth)));
    List<MatOfPoint> border = new ArrayList<MatOfPoint>();
    final int shift = (int)(mWidth * 0.005);
    border.add(new MatOfPoint(new Point(mWidth / 2 - shift, 0), new Point(mWidth / 2 + shift, 0),
            new Point(mWidth / 2 + shift, mHeight), new Point(mWidth / 2 - shift, mHeight)));
    Imgproc.fillPoly(comparisonFrame, border, new Scalar(255, 255, 255));

    Imgproc.putText(comparisonFrame, mResources.getString(R.string.original), new Point(mWidth * 0.1, mHeight * 0.1),
            Core.FONT_HERSHEY_SIMPLEX, 1.0, new Scalar(255, 255, 0));
    Imgproc.putText(comparisonFrame, mResources.getString(R.string.undistorted), new Point(mWidth * 0.6, mHeight * 0.1),
            Core.FONT_HERSHEY_SIMPLEX, 1.0, new Scalar(255, 255, 0));

    return comparisonFrame;
}
 
Example #8
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 #9
Source File: Detectable.java    From FTCVision with MIT License 6 votes vote down vote up
/**
 * Gets the average color of the object
 *
 * @param img      The image matrix, of any color size
 * @param imgSpace The image's color space
 * @return The average color of the region
 */
public Color averageColor(Mat img, ColorSpace imgSpace) {
    //Coerce values to stay within screen dimensions
    double leftX = MathUtil.coerce(0, img.cols() - 1, left());
    double rightX = MathUtil.coerce(0, img.cols() - 1, right());

    double topY = MathUtil.coerce(0, img.rows() - 1, top());
    double bottomY = MathUtil.coerce(0, img.rows() - 1, bottom());

    //Input points into array for calculation
    //TODO rectangular submatrix-based calculation isn't perfectly accurate when you have ellipses or weird shapes
    Mat subMat = img.submat((int) topY, (int) bottomY, (int) leftX, (int) rightX);

    //Calculate average and return new color instance
    return Color.create(Core.mean(subMat), imgSpace);
}
 
Example #10
Source File: FpsMeter.java    From AndroidDocumentScanner with MIT License 6 votes vote down vote up
public void measure() {
    if (!mIsInitialized) {
        init();
        mIsInitialized = true;
    } else {
        mFramesCouner++;
        if (mFramesCouner % STEP == 0) {
            long time = Core.getTickCount();
            double fps = STEP * mFrequency / (time - mprevFrameTime);
            mprevFrameTime = time;
            if (mWidth != 0 && mHeight != 0)
                mStrfps = FPS_FORMAT.format(fps) + " FPS@" + Integer.valueOf(mWidth) + "x" + Integer.valueOf(mHeight);
            else
                mStrfps = FPS_FORMAT.format(fps) + " FPS";
            Log.i(TAG, mStrfps);
        }
    }
}
 
Example #11
Source File: FpsMeter.java    From OpenCV-android with Apache License 2.0 6 votes vote down vote up
public void measure() {
    if (!mIsInitialized) {
        init();
        mIsInitialized = true;
    } else {
        mFramesCouner++;
        if (mFramesCouner % STEP == 0) {
            long time = Core.getTickCount();
            double fps = STEP * mFrequency / (time - mprevFrameTime);
            mprevFrameTime = time;
            if (mWidth != 0 && mHeight != 0)
                mStrfps = FPS_FORMAT.format(fps) + " FPS@" + Integer.valueOf(mWidth) + "x" + Integer.valueOf(mHeight);
            else
                mStrfps = FPS_FORMAT.format(fps) + " FPS";
            Log.i(TAG, mStrfps);
        }
    }
}
 
Example #12
Source File: FpsMeter.java    From Machine-Learning-Projects-for-Mobile-Applications with MIT License 6 votes vote down vote up
public void measure() {
    if (!mIsInitialized) {
        init();
        mIsInitialized = true;
    } else {
        mFramesCouner++;
        if (mFramesCouner % STEP == 0) {
            long time = Core.getTickCount();
            double fps = STEP * mFrequency / (time - mprevFrameTime);
            mprevFrameTime = time;
            if (mWidth != 0 && mHeight != 0)
                mStrfps = FPS_FORMAT.format(fps) + " FPS@" + Integer.valueOf(mWidth) + "x" + Integer.valueOf(mHeight);
            else
                mStrfps = FPS_FORMAT.format(fps) + " FPS";
            Log.i(TAG, mStrfps);
        }
    }
}
 
Example #13
Source File: FpsMeter.java    From MOAAP with MIT License 6 votes vote down vote up
public void measure() {
    if (!mIsInitialized) {
        init();
        mIsInitialized = true;
    } else {
        mFramesCouner++;
        if (mFramesCouner % STEP == 0) {
            long time = Core.getTickCount();
            double fps = STEP * mFrequency / (time - mprevFrameTime);
            mprevFrameTime = time;
            if (mWidth != 0 && mHeight != 0)
                mStrfps = FPS_FORMAT.format(fps) + " FPS@" + Integer.valueOf(mWidth) + "x" + Integer.valueOf(mHeight);
            else
                mStrfps = FPS_FORMAT.format(fps) + " FPS";
            Log.i(TAG, mStrfps);
        }
    }
}
 
Example #14
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 #15
Source File: CameraCalibrator.java    From OpenCV-AndroidSamples with MIT License 6 votes vote down vote up
public void calibrate() {
    ArrayList<Mat> rvecs = new ArrayList<Mat>();
    ArrayList<Mat> tvecs = new ArrayList<Mat>();
    Mat reprojectionErrors = new Mat();
    ArrayList<Mat> objectPoints = new ArrayList<Mat>();
    objectPoints.add(Mat.zeros(mCornersSize, 1, CvType.CV_32FC3));
    calcBoardCornerPositions(objectPoints.get(0));
    for (int i = 1; i < mCornersBuffer.size(); i++) {
        objectPoints.add(objectPoints.get(0));
    }

    Calib3d.calibrateCamera(objectPoints, mCornersBuffer, mImageSize,
            mCameraMatrix, mDistortionCoefficients, rvecs, tvecs, mFlags);

    mIsCalibrated = Core.checkRange(mCameraMatrix)
            && Core.checkRange(mDistortionCoefficients);

    mRms = computeReprojectionErrors(objectPoints, rvecs, tvecs, reprojectionErrors);
    Log.i(TAG, String.format("Average re-projection error: %f", mRms));
    Log.i(TAG, "Camera matrix: " + mCameraMatrix.dump());
    Log.i(TAG, "Distortion coefficients: " + mDistortionCoefficients.dump());
}
 
Example #16
Source File: FpsMeter.java    From MOAAP with MIT License 6 votes vote down vote up
public void measure() {
    if (!mIsInitialized) {
        init();
        mIsInitialized = true;
    } else {
        mFramesCouner++;
        if (mFramesCouner % STEP == 0) {
            long time = Core.getTickCount();
            double fps = STEP * mFrequency / (time - mprevFrameTime);
            mprevFrameTime = time;
            if (mWidth != 0 && mHeight != 0)
                mStrfps = FPS_FORMAT.format(fps) + " FPS@" + Integer.valueOf(mWidth) + "x" + Integer.valueOf(mHeight);
            else
                mStrfps = FPS_FORMAT.format(fps) + " FPS";
            Log.i(TAG, mStrfps);
        }
    }
}
 
Example #17
Source File: TestUtils.java    From go-bees with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Checks if two OpenCV Mats are equal.
 * The matrices must be equal size and type.
 * Floating-point mats are not supported.
 *
 * @param expected expected mat.
 * @param actual   actual mat.
 * @return true if they are equal.
 */
private static boolean equals(Mat expected, Mat actual) {
    if (expected.type() != actual.type() || expected.cols() != actual.cols()
            || expected.rows() != actual.rows()) {
        throw new UnsupportedOperationException(
                "Can not compare " + expected + " and " + actual);
    } else if (expected.depth() == CvType.CV_32F || expected.depth() == CvType.CV_64F) {
        throw new UnsupportedOperationException(
                "Floating-point mats must not be checked for exact match.");
    }
    // Subtract matrices
    Mat diff = new Mat();
    Core.absdiff(expected, actual, diff);
    // Count non zero pixels
    Mat reshaped = diff.reshape(1); // One channel
    int mistakes = Core.countNonZero(reshaped);
    // Free
    reshaped.release();
    diff.release();
    // Check mistakes
    return 0 == mistakes;
}
 
Example #18
Source File: HSVColorFilter.java    From DogeCV with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Process a image and return a mask
 * @param input - Input image to process
 * @param mask - Output mask
 */
@Override
public void process(Mat input, Mat mask) {
    // Copy the input to working mat
    workingMat = input.clone();
    // Convert the input to HSV color space
    Imgproc.cvtColor(workingMat,workingMat,Imgproc.COLOR_RGB2HSV_FULL);

    // Blur the imgae
    Imgproc.GaussianBlur(workingMat,workingMat,new Size(5,5),0);

    // Run a inRange mask using the color and range
    Scalar lower = new Scalar(perfect.val[0] - (range.val[0]/2), perfect.val[1] - (range.val[1]/2),perfect.val[2] - (range.val[2]/2));
    Scalar upper = new Scalar(perfect.val[0] + (range.val[0]/2), perfect.val[1] + (range.val[1]/2),perfect.val[2] + (range.val[2]/2));
    Core.inRange(workingMat,lower,upper,mask);
}
 
Example #19
Source File: RecognitionThread.java    From ml-authentication with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the recognized Student if the cosineSimilarity was above the threshold
 * @param featureVectorToRecognize
 * @return
 */
private synchronized List<Student> getMostSimilarStudentIfInThreshold(Mat featureVectorToRecognize){
    List<StudentImageCollectionEvent> studentImageCollectionEvents = studentImageCollectionEventDao.queryBuilder().where(StudentImageCollectionEventDao.Properties.MeanFeatureVector.isNotNull()).list();
    List<Student> studentsInThreshold = new ArrayList<>();
    for (StudentImageCollectionEvent studentImageCollectionEvent : studentImageCollectionEvents){
        Student currentStudent = studentImageCollectionEvent.getStudent();
        // Skip if the students are identical (same UniqueId)
        if (!areStudentsIdentical(currentStudent)){
            List<Float> featureVectorList = gson.fromJson(studentImageCollectionEvent.getMeanFeatureVector(), new TypeToken<List<Float>>(){}.getType());
            Mat featureVector = Converters.vector_float_to_Mat(featureVectorList);
            double dotProduct = featureVector.dot(featureVectorToRecognize);
            double normFeatureVector = Core.norm(featureVector, Core.NORM_L2);
            double normFeatureVectorToRecognize = Core.norm(featureVectorToRecognize, Core.NORM_L2);
            double cosineSimilarity = dotProduct / (normFeatureVector * normFeatureVectorToRecognize);
            double absoluteCosineSimilarity = Math.abs(cosineSimilarity);
            Log.i(getClass().getName(), "getMostSimilarStudentIfInThreshold: absoluteCosineSimilarity: " + absoluteCosineSimilarity + " with Student: " + currentStudent.getUniqueId());
            if (absoluteCosineSimilarity > SIMILARITY_THRESHOLD){
                studentsInThreshold.add(currentStudent);
            }
        } else {
            Log.i(getClass().getName(), "getMostSimilarStudentIfInThreshold: currentStudent: " + currentStudent.getUniqueId() + " was skipped because it is identical with the student: " + student.getUniqueId());
        }
    }
    return studentsInThreshold;
}
 
Example #20
Source File: MainActivity.java    From MOAAP with MIT License 6 votes vote down vote up
void Sobel() {
    Mat grayMat = new Mat();
    Mat sobel = new Mat(); //Mat to store the final result

    //Matrices to store gradient and absolute gradient respectively
    Mat grad_x = new Mat();
    Mat abs_grad_x = new Mat();

    Mat grad_y = new Mat();
    Mat abs_grad_y = new Mat();

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

    //Calculating gradient in horizontal direction
    Imgproc.Sobel(grayMat, grad_x, CvType.CV_16S, 1, 0, 3, 1, 0);

    //Calculating gradient in vertical direction
    Imgproc.Sobel(grayMat, grad_y, CvType.CV_16S, 0, 1, 3, 1, 0);

    //Calculating absolute value of gradients in both the direction
    Core.convertScaleAbs(grad_x, abs_grad_x);
    Core.convertScaleAbs(grad_y, abs_grad_y);

    //Calculating the resultant gradient
    Core.addWeighted(abs_grad_x, 0.5, abs_grad_y, 0.5, 1, sobel);

    //Converting Mat back to Bitmap
    Utils.matToBitmap(sobel, currentBitmap);
    imageView.setImageBitmap(currentBitmap);
}
 
Example #21
Source File: Eigenfaces.java    From Android-Face-Recognition-with-Deep-Learning-Library with Apache License 2.0 6 votes vote down vote up
public String recognize(Mat img, String expectedLabel){
    // Ignore
    img = img.reshape(1,1);
    // Subtract mean
    img.convertTo(img, CvType.CV_32F);
    Core.subtract(img, Psi, img);
    // Project to subspace
    Mat projected = getFeatureVector(img);
    // Save all points of image for tSNE
    img.convertTo(img, CvType.CV_8U);
    addImage(projected, expectedLabel, true);
    //addImage(projected, expectedLabel);
    Mat distance = new Mat(Omega.rows(), 1, CvType.CV_64FC1);
    for (int i=0; i<Omega.rows(); i++){
        double dist = Core.norm(projected.row(0), Omega.row(i), Core.NORM_L2);
        distance.put(i, 0, dist);
    }
    Mat sortedDist = new Mat(Omega.rows(), 1, CvType.CV_8UC1);
    Core.sortIdx(distance, sortedDist, Core.SORT_EVERY_COLUMN + Core.SORT_ASCENDING);
    // Give back the name of the found person
    int index = (int)(sortedDist.get(0,0)[0]);
    return labelMap.getKey(labelList.get(index));
}
 
Example #22
Source File: ImgprocessUtils.java    From classchecks with Apache License 2.0 5 votes vote down vote up
/**
 * 
* @Title: gammaAdjust 
* @Description: gamma校正
* @param grayImg
* @return
* Mat 
* @throws
 */
public static Mat gammaAdjust(Mat grayImg) {
	
	Mat X = new Mat();
	grayImg.convertTo(X, CvType.CV_32FC1);
	Mat I = new Mat();
    float gamma = 1/2.2f;
    Core.pow(X, gamma, I);
    
    Mat result = norm_0_255(I);
    return result;
}
 
Example #23
Source File: ColorBlobDetector.java    From hand_finger_recognition_android with MIT License 5 votes vote down vote up
public void process(Mat rgbaImage) {
    Imgproc.pyrDown(rgbaImage, mPyrDownMat);
	Imgproc.pyrDown(mPyrDownMat, mPyrDownMat);

    Imgproc.cvtColor(mPyrDownMat, mHsvMat, Imgproc.COLOR_RGB2HSV_FULL);

    Core.inRange(mHsvMat, mLowerBound, mUpperBound, mMask);
    Imgproc.dilate(mMask, mDilatedMask, new Mat());

    List<MatOfPoint> contours = new ArrayList<MatOfPoint>();

    Imgproc.findContours(mDilatedMask, contours, mHierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);

    // Find max contour area
    double maxArea = 0;
    Iterator<MatOfPoint> each = contours.iterator();
    while (each.hasNext()) {
        MatOfPoint wrapper = each.next();
        double area = Imgproc.contourArea(wrapper);
        if (area > maxArea)
            maxArea = area;
    }

    // Filter contours by area and resize to fit the original image size
    mContours.clear();
    each = contours.iterator();
    while (each.hasNext()) {
        MatOfPoint contour = each.next();
        if (Imgproc.contourArea(contour) > mMinContourArea*maxArea) {
            Core.multiply(contour, new Scalar(4,4), contour);
            mContours.add(contour);
        }
    }
}
 
Example #24
Source File: AirlightEstimate.java    From OptimizedImageEnhance with MIT License 5 votes vote down vote up
private static double calculateScore(Mat im) {
	MatOfDouble mean = new MatOfDouble();
	MatOfDouble std = new MatOfDouble();
	Core.meanStdDev(im, mean, std);
	double[] means = mean.get(0, 0);
	double[] stds = std.get(0, 0);
	double score = 0.0;
	for (int i = 0; i < means.length; i++) score += means[i] - stds[i];
	return score;
}
 
Example #25
Source File: OpenCVNonMavenExamples.java    From Java-for-Data-Science with MIT License 5 votes vote down vote up
public OpenCVNonMavenExamples() {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        enhanceImageBrightness();
        enhanceImageContrast();
//        sharpenImage();
        smoothImage();
        resizeImage();
        convertImage();
//        noiseRemoval();
//        denoise();
//        convertToTIFF();
    }
 
Example #26
Source File: FpsMeter.java    From OpenCV-Android-Object-Detection with MIT License 5 votes vote down vote up
public void init() {
    mFramesCouner = 0;
    mFrequency = Core.getTickFrequency();
    mprevFrameTime = Core.getTickCount();
    mStrfps = "";

    mPaint = new Paint();
    mPaint.setColor(Color.BLUE);
    mPaint.setTextSize(20);
}
 
Example #27
Source File: Main.java    From Face-Recognition with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args)
{
	// load the native OpenCV library
	System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
	
	launch(args);
}
 
Example #28
Source File: Cluster.java    From opencv-fun with GNU Affero General Public License v3.0 5 votes vote down vote up
public static List<Mat> cluster(Mat cutout, int k) {
	Mat samples = cutout.reshape(1, cutout.cols() * cutout.rows());
	Mat samples32f = new Mat();
	samples.convertTo(samples32f, CvType.CV_32F, 1.0 / 255.0);
	
	Mat labels = new Mat();
	TermCriteria criteria = new TermCriteria(TermCriteria.COUNT, 100, 1);
	Mat centers = new Mat();
	Core.kmeans(samples32f, k, labels, criteria, 1, Core.KMEANS_PP_CENTERS, centers);		
	return showClusters(cutout, labels, centers);
}
 
Example #29
Source File: FpsMeter.java    From sudokufx with Apache License 2.0 5 votes vote down vote up
public void init() {
    mFramesCouner = 0;
    mFrequency = Core.getTickFrequency();
    mprevFrameTime = Core.getTickCount();
    mStrfps = "";

    mPaint = new Paint();
    mPaint.setColor(Color.BLUE);
    mPaint.setTextSize(20);
}
 
Example #30
Source File: OpenCVoperation.java    From Human-hair-detection with Apache License 2.0 5 votes vote down vote up
public OpenCVoperation(String rootDirectory,String sourceFileName,String[] OutputFileNames)
{
     resultDirectory = rootDirectory;
     fileName =sourceFileName;
     grabcutOutput = "face2_grabcut.png";
     skinDetectionOutput = "face3_skindetection.png";
     /*--existing file names
     grabcut_QuantizedOutput = "face5_grabcut_quantized.png";
     skin_QuantizedOutput = "face6_skin_quantized.png";
     finalImage_Output = "face7_output.png";
     maskOutput ="skin_mask.png";
     maskRgbOutput = "skin_mask_rgb.png";
     contourMaskOutput="face8_contour_image.png";
     erosionOutput ="erosion_image.png";
     dilationOutput ="dilation_image.png";
     */
     
     dilationOutput ="dilation_image.png";
     maskOutput ="skin_mask.png";
     maskRgbOutput = "skin_mask_rgb.png";
     grabcut_QuantizedOutput = OutputFileNames[2]+".png";
     skin_QuantizedOutput = OutputFileNames[3]+".png";
     morphingOutput = OutputFileNames[4]+".png";
     finalImage_Output = OutputFileNames[5]+".png";
     erosionOutput =OutputFileNames[6]+".png";
     contourMaskOutput=OutputFileNames[7]+".png";
     FinalImageWithDilutionOutput =OutputFileNames[8]+".png";
     
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
}