Featured

Java: Question and answer for interviewing

Nguồn: https://www.edureka.co/blog/interview-questions/java-interview-questions/ và https://congdongjava.com/forum/threads/java-thread-luồng-trong-java.714/

Cảm ơn 2 nguồn rất nhiều, thông tin rất rõ và bổ ích

  1. Static là gì? Nếu để static thì sao mà non static thì sao? Trả lời: Static là 1 keyword của java để định nghĩa method hoặc variable có thể được truy cập sử dụng mà không cần tạo instance của Class. Vd: ta có thể sử dụng static method B của class A thông qua cách gọi A.B() mà ko cần tạo instance như “a = new A(); a.B();”
  2. Hàm main trong 1 class là gì? Tại sao cần hàm main()? Trả lời: Hàm main là 1 hàm mặc định trong 1 class, hàm main này sẽ được JVM tìm và phát hiện ra để chạy ứng dụng. It is the method where the main execution occurs.
  3. Tại sao Java không phải là 100% OOP? Trả lời: Bởi vì trong java có các kiểu dữ lieu nguyên thủy Boolean, long, string, int, … không phải là 1 object.
  4. Constructor trong Java là gì? Trả lời: constructor là 1 block of code thường được xài để khởi tạo object, Constructor phải có tên giống với tên của class và không có kiểu trả về, nó được tự động gọi khi object được tạo. Có 2 kiểu constructor: default(constructor rỗng, ko có gì) và parameterized(khởi tạo có biến).
  5. Singleton class là gì và làm thế nào để tạo 1 class singleton? Trả lời: Singleton là một trong nhưững design pattern đơn giản nhất, để đảm bảo trong 1 chương trình chỉ có 1 instance của 1 class được tạo. Singleton class có thể được tạo bang cách cho constructor private, và tạo 1 method public static getInstance() mà có thể access từ client đêể gọi và method này sẽ tạo instance nếu chưa khởi tạo và ngược lại. VD:

Continue reading “Java: Question and answer for interviewing”

[Android] [OpenCV] Adding OpenCV to Native C code through CMake on Android Studio

First, follow steps on Google Official site: https://developer.android.com/studio/projects/add-native-code?utm_source=android-studio

 

Next:

 

There are two ways of including OpenCV.

Git/Simpler Way

Visit https://github.com/ahasbini/Android-OpenCV for more details.

Manual/Advanced Way

To include OpenCV libraries into Android Studio Project, its best to create a new Library Module in the project and port the files from OpenCV Android SDK bundle into it:

  1. Create a new module by selecting File>New Module.
  2. Select “Android Library”, and then enter the details:
    • Library name: OpenCV
    • Module name: opencv
    • Package name: org.opencv
  3. Once the new module created, copy the contents of path_to_opencv_sdk/sdk/java/srcdirectory into path_to_your_project/opencv/src/main/java.
  4. Under main, create the following directly path: aidl/org/opencv/engine and move main/java/org/opencv/engine/OpenCVEngineInterface.aidl into it.
  5. Copy the contents of path_to_opencv_sdk/sdk/java/res into path_to_your_project/opencv/src/main/res.
  6. Create sdk folder inside path_to_your_project/opencv/src/ and copy path_to_opencv_sdk/sdk/native folder into it.
  7. Within the opencv module, create CMakeLists.txt file and add the following lines in the following order:

cmake_minimum_required(VERSION 3.4.1)
set(OpenCV_DIR "src/sdk/native/jni")
find_package(OpenCV REQUIRED)
message(STATUS "OpenCV libraries: ${OpenCV_LIBS}")
include_directories(${OpenCV_INCLUDE_DIRS})

  1. Within the opencv module, edit the build.gradle file as such:

...
android {
    ...

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 25
        versionCode 3200
        versionName "3.2.0"

        ...

        externalNativeBuild {
            cmake {
                cppFlags "-frtti -fexceptions"
            }
        }
    }
    buildTypes {
        ...
    }
    externalNativeBuild {
        cmake {
            path "CMakeLists.txt"
        }
    }
    sourceSets {
        main {
            jni.srcDirs = [jni.srcDirs, 'src/sdk/native/jni/include']
            jniLibs.srcDirs = [jniLibs.srcDirs, 'src/sdk/native/3rdparty/libs', 'src/sdk/native/libs']
        }
    }
}
...

  1. Within the app (application module, could be another name) module, create/edit CMakeLists.txt file and add the following lines in the following order (Note the different path set to OpenCV_DIR):

set(OpenCV_DIR "../opencv/src/sdk/native/jni")
find_package(OpenCV REQUIRED)
message(STATUS "OpenCV libraries: ${OpenCV_LIBS}")
target_link_libraries(YOUR_TARGET_LIB ${OpenCV_LIBS})

  1. Within the app (application module, could be another name) module, edit the build.gradlefile as such:

...    
android {
    ...
    defaultConfig {
        ...
        externalNativeBuild {
            cmake {
                cppFlags "-frtti -fexceptions"
        }
    }
    buildTypes {
        ...
    }
    externalNativeBuild {
        cmake {
            path "CMakeLists.txt"
        }
    }
}

dependencies {
    ...
    compile project(':opencv')
}

  1. Do a gradle sync, and now the OpenCV native libs, header files and Java wrapper classes are included.

When project is built and apk is launched, you could inspect the packaged apk under path_to_project/path_to_app_module/build/output/ (drag the apk onto the text editor tabs of Android Studio)

APK Inspection

You should see a libopencv_java3.so under each abi architecture folder.

Initialize the OpenCV SDK in your java class :

public class MyClass {

    static {
        if (BuildConfig.DEBUG) {
            OpenCVLoader.initDebug();
        }
    }

    ...
}

And you should see within logcat messages specifying the OpenCV has been loaded (the first error is normal):

05-10 10:42:31.451 D/OpenCV/StaticHelper: Trying to get library list
05-10 10:42:31.452 E/OpenCV/StaticHelper: OpenCV error: Cannot load info library for OpenCV
05-10 10:42:31.452 D/OpenCV/StaticHelper: Library list: ""
05-10 10:42:31.452 D/OpenCV/StaticHelper: First attempt to load libs
05-10 10:42:31.452 D/OpenCV/StaticHelper: Trying to init OpenCV libs
05-10 10:42:31.452 D/OpenCV/StaticHelper: Trying to load library opencv_java3
05-10 10:42:32.031 D/OpenCV/StaticHelper: Library opencv_java3 loaded
05-10 10:42:32.031 D/OpenCV/StaticHelper: First attempt to load libs is OK
05-10 10:42:32.045 I/OpenCV/StaticHelper: General configuration for OpenCV 3.2.0 =====================================
05-10 10:42:32.045 I/OpenCV/StaticHelper:   Version control:               3.2.0
05-10 10:42:32.045 I/OpenCV/StaticHelper:   Platform:
05-10 10:42:32.045 I/OpenCV/StaticHelper:     Timestamp:                   2016-12-23T13:04:49Z
05-10 10:42:32.045 I/OpenCV/StaticHelper:     Host:                        Linux 4.8.0-25-generic x86_64
05-10 10:42:32.045 I/OpenCV/StaticHelper:     Target:                      Linux 1 x86_64
05-10 10:42:32.045 I/OpenCV/StaticHelper:     CMake:                       2.8.12.2
05-10 10:42:32.045 I/OpenCV/StaticHelper:     CMake generator:             Ninja
05-10 10:42:32.045 I/OpenCV/StaticHelper:     CMake build tool:            /usr/bin/ninja
05-10 10:42:32.045 I/OpenCV/StaticHelper:     Configuration:               Release
05-10 10:42:32.045 I/OpenCV/StaticHelper:   C/C++:
05-10 10:42:32.045 I/OpenCV/StaticHelper:     Built as dynamic libs?:      NO
05-10 10:42:32.045 I/OpenCV/StaticHelper:     C++ Compiler:                /usr/bin/ccache /opt/android/android-ndk-r10e/toolchains/x86_64-4.9/prebuilt/linux-x86_64/bin/x86_64-linux-android-g++ (ver 4.9)

[Android] [OpenCV] Tutorial Part 2 – Understanding Available Packages of OpenCV for Android SDK

In the previous tutorial, you learnt about the file structure of OpenCV SDK for Android. Now, we will learn the packages which are available for us to use in OpenCV SDK for Android. At the end of this tutorial, you will definitely know what OpenCV for android has to offer.

Each package is imported like this:

import org.opencv.android.BaseLoaderCallback;

import org.opencv.android.CameraBridgeViewBase;

import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame;

import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2;

import org.opencv.android.LoaderCallbackInterface;

import org.opencv.android.OpenCVLoader;

import org.opencv.core.Mat;

Each packages has java classes which contain functions which you use.

Continue reading “[Android] [OpenCV] Tutorial Part 2 – Understanding Available Packages of OpenCV for Android SDK”

[Android] [OpenCV] Tutorial Part 1 – OpenCV SDK for Android File Structure

In this tutorial, you will learn about the file structure of OpenCV SDK for Android. The information here is very short and lacks details. My purpose here is to provide just enough information to get going with the rest of the tutorials. I highly recommend reading more about the folders, algorithms, libraries and classes on your own.

So you have downloaded SDK but you may be curious what the SDK files do. Lets see to that now. You can skip this tutorial if you are interested in going directly to the development. Continue reading “[Android] [OpenCV] Tutorial Part 1 – OpenCV SDK for Android File Structure”

[Android] [OpenCV] Setup OpenCV and example for beginner

Setup and first look for beginner:

 

A Beginner’s Guide to Setting up OpenCV Android Library on Android Studio

I recently started a project that involved working with OpenCV on Android. Most of the guides on setting up the library on Android were outdated or not complete. So, after getting multiple requests from team mates on how to set this up, I decided to just write a dead simple guide on this.

Image Detection (Source)

Step 1: Download OpenCV Android Library

Go to the OpenCV Android Sourceforge page and download the latest OpenCV Android library. As at the time of writing this post, the latest available version was 3.4.1.

When the download completes, you should extract the contents of the zip file into a folder.

Step 2: Setup project

Create a new Android project using Android Studio only if you have not created one already for your computer vision project.

Note: Skip this step if you already have an Android project you want to use the OpenCV library in.

Step 3: Import OpenCV Module

After successfully creating an Android project, it is time to import the OpenCV module into your Android project. Click on File -> New -> Import Module…

It should bring up a popup like the image below where you can select the path to the module you want to import.

Browse to the folder where you extracted the OpenCV Android library zip file contents. Select the java folder inside of the sdk folder.

After selecting the correct path and clicking OK, you should get a screen like the image below.

Click on Next to go to the next screen. On the next screen (the image below) you should leave the default options checked and click on Finish to complete the module import.

Step 4: Fixing Gradle Sync Errors

You should get a Gradle build error after you finish importing the OpenCV library. This happens because the library is using an old Android SDK that you probably don’t have installed yet.

To quickly fix this error, switch from the Android pane to the Project pane on the left side of Android Studio.

Browse to OpenCV library module and open its build.gradle file.

To fix the error, you just have to change the compileSdkVersion and targetSdkVersion to the latest Android SDK version or the one you have installed on your PC. After changing the version you should click on the syncbutton so that Gradle can sync the project.

Quick tip: buildToolsVersion can be ignored

Step 5: Add the OpenCV Dependency

To work with the OpenCV Android library, you have to add it to your appmodule as a dependency. To easily do this on Android Studio, click on File -> Project Structure.

When the project structure dialog opens, click on the app module or any other module that you want to use OpenCV library in.

After navigating to the module, click on the Dependencies tab. You should see a green plus button on the far right of the dialog, click on it and select Module dependency.

When the choose modules dialog opens, select the OpenCV library module and click on OK.

When you return to the dependencies page, confirm that the module was actually added as a dependency then click on the OK button to continue.

Step 6: Add Native Libraries

On your file explorer, navigate to the folder where you extracted the content of the OpenCV Android library zip file. Open the sdk folder and then the native folder (Use the image below as a guide).

Copy the libs folder in the native folder over to your project app module main folder (Usually ProjectName/app/src/main).

Rename the libs folder you just copied into your project to jniLibs.

Step 7: Add Required Permissions

To successfully use OpenCV, your app should have the camera permission added to its AndroidManifest.xml file.

Tip: Don’t forget to request for the camera permission at runtime on Android 6 and above.

<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera" android:required="false"/>
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>
<uses-feature android:name="android.hardware.camera.front" android:required="false"/>
<uses-feature android:name="android.hardware.camera.front.autofocus" android:required="false"/> 

Step 8: Try out Sample

To confirm that you successfully integrated the OpenCV Android library, you can try out one of the samples included in the library zip file.

Let’s try out the color-blob-detection sample. You can see the sample in action below:

Quickly update your app main activity with the code below.

package com.mobymagic.opencvproject;

import java.util.List;

import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader;
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.MatOfPoint;
import org.opencv.core.Rect;
import org.opencv.core.Scalar;
import org.opencv.core.Size;
import org.opencv.android.CameraBridgeViewBase;
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2;
import org.opencv.imgproc.Imgproc;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnTouchListener;
import android.view.SurfaceView;

public class MainActivity extends Activity implements OnTouchListener, CvCameraViewListener2 {
    private static final String  TAG              = "MainActivity";

    private boolean              mIsColorSelected = false;
    private Mat                  mRgba;
    private Scalar               mBlobColorRgba;
    private Scalar               mBlobColorHsv;
    private ColorBlobDetector    mDetector;
    private Mat                  mSpectrum;
    private Size                 SPECTRUM_SIZE;
    private Scalar               CONTOUR_COLOR;

    private CameraBridgeViewBase mOpenCvCameraView;

    private BaseLoaderCallback  mLoaderCallback = new BaseLoaderCallback(this) {
        @Override
        public void onManagerConnected(int status) {
            switch (status) {
                case LoaderCallbackInterface.SUCCESS:
                {
                    Log.i(TAG, "OpenCV loaded successfully");
                    mOpenCvCameraView.enableView();
                    mOpenCvCameraView.setOnTouchListener(MainActivity.this);
                } break;
                default:
                {
                    super.onManagerConnected(status);
                } break;
            }
        }
    };

    public MainActivity() {
        Log.i(TAG, "Instantiated new " + this.getClass());
    }

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        Log.i(TAG, "called onCreate");
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

        setContentView(R.layout.color_blob_detection_surface_view);

        mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.color_blob_detection_activity_surface_view);
        mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);
        mOpenCvCameraView.setCvCameraViewListener(this);
    }

    @Override
    public void onPause()
    {
        super.onPause();
        if (mOpenCvCameraView != null)
            mOpenCvCameraView.disableView();
    }

    @Override
    public void onResume()
    {
        super.onResume();
        if (!OpenCVLoader.initDebug()) {
            Log.d(TAG, "Internal OpenCV library not found. Using OpenCV Manager for initialization");
            OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_0_0, this, mLoaderCallback);
        } else {
            Log.d(TAG, "OpenCV library found inside package. Using it!");
            mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
        }
    }

    public void onDestroy() {
        super.onDestroy();
        if (mOpenCvCameraView != null)
            mOpenCvCameraView.disableView();
    }

    public void onCameraViewStarted(int width, int height) {
        mRgba = new Mat(height, width, CvType.CV_8UC4);
        mDetector = new ColorBlobDetector();
        mSpectrum = new Mat();
        mBlobColorRgba = new Scalar(255);
        mBlobColorHsv = new Scalar(255);
        SPECTRUM_SIZE = new Size(200, 64);
        CONTOUR_COLOR = new Scalar(255,0,0,255);
    }

    public void onCameraViewStopped() {
        mRgba.release();
    }

    public boolean onTouch(View v, MotionEvent event) {
        int cols = mRgba.cols();
        int rows = mRgba.rows();

        int xOffset = (mOpenCvCameraView.getWidth() - cols) / 2;
        int yOffset = (mOpenCvCameraView.getHeight() - rows) / 2;

        int x = (int)event.getX() - xOffset;
        int y = (int)event.getY() - yOffset;

        Log.i(TAG, "Touch image coordinates: (" + x + ", " + y + ")");

        if ((x < 0) || (y < 0) || (x > cols) || (y > rows)) return false;

        Rect touchedRect = new Rect();

        touchedRect.x = (x>4) ? x-4 : 0;
        touchedRect.y = (y>4) ? y-4 : 0;

        touchedRect.width = (x+4 < cols) ? x + 4 - touchedRect.x : cols - touchedRect.x;
        touchedRect.height = (y+4 < rows) ? y + 4 - touchedRect.y : rows - touchedRect.y;

        Mat touchedRegionRgba = mRgba.submat(touchedRect);

        Mat touchedRegionHsv = new Mat();
        Imgproc.cvtColor(touchedRegionRgba, touchedRegionHsv, Imgproc.COLOR_RGB2HSV_FULL);

        // Calculate average color of touched region
        mBlobColorHsv = Core.sumElems(touchedRegionHsv);
        int pointCount = touchedRect.width*touchedRect.height;
        for (int i = 0; i < mBlobColorHsv.val.length; i++)
            mBlobColorHsv.val[i] /= pointCount;

        mBlobColorRgba = converScalarHsv2Rgba(mBlobColorHsv);

        Log.i(TAG, "Touched rgba color: (" + mBlobColorRgba.val[0] + ", " + mBlobColorRgba.val[1] +
                ", " + mBlobColorRgba.val[2] + ", " + mBlobColorRgba.val[3] + ")");

        mDetector.setHsvColor(mBlobColorHsv);

        Imgproc.resize(mDetector.getSpectrum(), mSpectrum, SPECTRUM_SIZE, 0, 0, Imgproc.INTER_LINEAR_EXACT);

        mIsColorSelected = true;

        touchedRegionRgba.release();
        touchedRegionHsv.release();

        return false; // don't need subsequent touch events
    }

    public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
        mRgba = inputFrame.rgba();

        if (mIsColorSelected) {
            mDetector.process(mRgba);
            List<MatOfPoint> contours = mDetector.getContours();
            Log.e(TAG, "Contours count: " + contours.size());
            Imgproc.drawContours(mRgba, contours, -1, CONTOUR_COLOR);

            Mat colorLabel = mRgba.submat(4, 68, 4, 68);
            colorLabel.setTo(mBlobColorRgba);

            Mat spectrumLabel = mRgba.submat(4, 4 + mSpectrum.rows(), 70, 70 + mSpectrum.cols());
            mSpectrum.copyTo(spectrumLabel);
        }

        return mRgba;
    }

    private Scalar converScalarHsv2Rgba(Scalar hsvColor) {
        Mat pointMatRgba = new Mat();
        Mat pointMatHsv = new Mat(1, 1, CvType.CV_8UC3, hsvColor);
        Imgproc.cvtColor(pointMatHsv, pointMatRgba, Imgproc.COLOR_HSV2RGB_FULL, 4);

        return new Scalar(pointMatRgba.get(0, 0));
    }
}

Then create a new class called ColorBlobDetector and copy the code below into it.

package com.mobymagic.opencvproject;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.MatOfPoint;
import org.opencv.core.Scalar;
import org.opencv.imgproc.Imgproc;

public class ColorBlobDetector {
    // Lower and Upper bounds for range checking in HSV color space
    private Scalar mLowerBound = new Scalar(0);
    private Scalar mUpperBound = new Scalar(0);
    // Minimum contour area in percent for contours filtering
    private static double mMinContourArea = 0.1;
    // Color radius for range checking in HSV color space
    private Scalar mColorRadius = new Scalar(25,50,50,0);
    private Mat mSpectrum = new Mat();
    private List<MatOfPoint> mContours = new ArrayList<MatOfPoint>();

    // Cache
    Mat mPyrDownMat = new Mat();
    Mat mHsvMat = new Mat();
    Mat mMask = new Mat();
    Mat mDilatedMask = new Mat();
    Mat mHierarchy = new Mat();

    public void setColorRadius(Scalar radius) {
        mColorRadius = radius;
    }

    public void setHsvColor(Scalar hsvColor) {
        double minH = (hsvColor.val[0] >= mColorRadius.val[0]) ? hsvColor.val[0]-mColorRadius.val[0] : 0;
        double maxH = (hsvColor.val[0]+mColorRadius.val[0] <= 255) ? hsvColor.val[0]+mColorRadius.val[0] : 255;

        mLowerBound.val[0] = minH;
        mUpperBound.val[0] = maxH;

        mLowerBound.val[1] = hsvColor.val[1] - mColorRadius.val[1];
        mUpperBound.val[1] = hsvColor.val[1] + mColorRadius.val[1];

        mLowerBound.val[2] = hsvColor.val[2] - mColorRadius.val[2];
        mUpperBound.val[2] = hsvColor.val[2] + mColorRadius.val[2];

        mLowerBound.val[3] = 0;
        mUpperBound.val[3] = 255;

        Mat spectrumHsv = new Mat(1, (int)(maxH-minH), CvType.CV_8UC3);

        for (int j = 0; j < maxH-minH; j++) {
            byte[] tmp = {(byte)(minH+j), (byte)255, (byte)255};
            spectrumHsv.put(0, j, tmp);
        }

        Imgproc.cvtColor(spectrumHsv, mSpectrum, Imgproc.COLOR_HSV2RGB_FULL, 4);
    }

    public Mat getSpectrum() {
        return mSpectrum;
    }

    public void setMinContourArea(double area) {
        mMinContourArea = area;
    }

    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);
            }
        }
    }

    public List<MatOfPoint> getContours() {
        return mContours;
    }
}

Finally, update your app main activity layout file with the layout code below.

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <org.opencv.android.JavaCameraView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/color_blob_detection_activity_surface_view" />

</FrameLayout>

Step 9: Using OpenCV Manager

Because you are bundling native libraries in your app APK, you will end up with a very large app APK size.

One way to solve this is to use ABI splits, so you only have the neccessary libraries needed for each device in an APK.

The other way around the size issue is to use the OpenCV Manager. In the folder where you extracted the library contents into, there is a folder called apk that contains the OpenCV manager for various architectures.

Select the APK with the right architecture of your test device and use ADB via command prompt/line to install it on your device.

Step 10: Test the App

Finally, hit the run button and run the app on your test device.

Note: Don’t forget to grant camera permission on Android 6 and above.

That is all.

Source: https://android.jlelse.eu/a-beginners-guide-to-setting-up-opencv-android-library-on-android-studio-19794e220f3c

 

Selenium Webdriver – 20 Coding Tips to Improve Quality

Selenium Webdriver is a powerful automation tool for testing web applications. It’s an open source library bundled with a rich set of features. Using it for testing a website is just like simulating the actions of a real user. All these abilities together make it a perfect tool for automation. But you need proper guidance to get the best out of it. In this blog post, we’ve assembled some of the best Selenium Webdriver coding tips for software testers.

Continue reading “Selenium Webdriver – 20 Coding Tips to Improve Quality”

Cảm ơn vì đã nói câu từ chối

Bạn đã từng tham dự những buổi phỏng vấn hết sức cam go và khi tưởng chừng như công việc đã gần trong tầm tay thì lại nhận được thư từ chối từ bộ phận tuyển dụng? Chắc hẳn nhiều người sẽ cảm thấy rất thất vọng, hụt hẫng, thậm chí là có cảm giác … giận vô cùng!

Nhưng có bao giờ bạn tạm gác qua những cảm xúc lẫn lộn của bản thân để một lần thử cảm ơn vì công ty đã thông báo việc từ chối nhận bạn vào làm?

 

Nghe chừng như vô lý quá, nhưng hãy thử suy xét một vài lý do sau để hiểu hơn vì sao bạn nên gửi lời cảm ơn đến bộ phận tuyển dụng sau khi phỏng vấn thất bại nhé.

Lời cảm ơn chính là cơ hội trong tương lai

Trước hết, hãy chấp nhận thực tế là bạn không có được công việc như kỳ vọng. Việc nuốt trôi cảm giác thất bại thật không dễ dàng gì và những gì bạn muốn làm là hét thật to, giải toả nỗi bực dọc với người đã phỏng vấn bạn vì quyết định của họ. Thế nhưng, hãy tìm đến những người bạn thân để giải bày tâm sự!

Còn với công ty đã từ chối mình, hãy gửi một email ngắn gọn để hồi đáp lại việc thông báo kết quả phỏng vấn. Vì một lý do nào đó mà bạn chưa thành công trong lần phỏng vấn này nhưng lời cảm ơn của bạn sẽ gây ấn tượng mạnh mẽ về sự chuyên nghiệp và nghiêm túc trong nghề nghiệp của bạn với nhà tuyển dụng. Và chắc bạn không ngờ tới, nhưng thái độ của bạn thông qua việc cảm ơn được đánh giá rất cao và hồ sơ của bạn sẽ có thể được âm thầm chuyển sang những vị trí khác phù hợp hơn trong mạng lưới hoặc các mối quan hệ quen biết của người tuyển dụng. Bạn đã nhìn thấy cơ hội của mình qua một việc rất nhỏ chưa?

Nhưng tôi thất bại rồi, phải nói những gì khi cảm ơn đây?

Bạn không cần phải giả vờ hồ hởi, tươi vui khi viết email cảm ơn vì sự thật hiển nhiên là bạn chưa thành công trong vị trí vừa phỏng vấn. Việc viết email với giọng văn quá tích cực lại khiến người nhận cảm thấy bạn chỉ đang cố gắng quá sức mà thôi. Hãy tỏ ra bình thường và gửi lời cảm ơn về những điều thực tế nhất như cảm ơn vì người tuyển dụng đã bỏ thời gian để phỏng vấn bạn, cảm ơn vì bạn đã có cơ hội được ghé thăm công ty và có thêm những thông tin thú vị xuyên suốt buổi phỏng vấn và cảm ơn vì bạn đã được thông báo kết quả đúng thời hạn để bạn không phải mất thời gian chờ đợi thêm và có thể tiếp tục tìm kiếm những cơ hội khác.

Và nếu bạn muốn giải toả thắc mắc vì sao mình chưa thành công cho vị trí vừa ứng tuyển, hãy nhân cơ hội này để đặt ra câu hỏi với bộ phận tuyển dụng. Bạn hoàn toàn có thể chủ động tìm hiểu xem “Có điều gì còn thiếu sót trong kinh nghiệm làm việc của tôi hoặc đâu là những điểm mà tôi chưa phù hợp cho vị trí ABC?” thông qua việc xin ý kiến từ công ty bạn đã tham dự phỏng vấn. Điều này vừa giúp cho bạn thôi băn khoăn vì sao bạn chưa trúng tuyển, đồng thời cũng cung cấp cho bạn góc nhìn khách quan từ vị trí nhà tuyển dụng để giúp bạn cải thiện thêm những kỹ năng và kinh nghiệm của mình trong tương lai.

Đừng quên việc giữ kết nối với nhà tuyển dụng

Việc bạn chưa thành công trong lần ứng tuyển này không có nghĩa là bạn sẽ không còn một cơ hội nào khác để tham gia công ty mà bạn yêu thích. Có rất nhiều lý do cả chủ quan lẫn khách quan để nhà tuyển dụng đưa ra quyết định sau cùng nhưng sẽ hoàn toàn không thừa nếu bạn tỏ thành ý giữ kết nối với họ bằng một câu nói đơn giản như “Hy vọng những kinh nghiệm và kỹ năng của tôi sẽ phù hợp với các vị trí khác trong thời gian sắp tới”. Theo chia sẻ của nhiều nhà tuyển dụng, việc chủ động bày tỏ lời đề nghị này từ ứng viên mang lại ấn tượng mạnh mẽ khiến họ nhớ đến những ứng viên này nhanh nhất khi phát sinh nhu cầu tuyển dụng mới có liên quan. Thậm chí, trong nhiều trường hợp, khi ứng viên xuất sắc hơn từ chối nhận việc vào phút cuối, nhà tuyển dụng ngay lập tức liên lạc lại với bạn để trao cho bạn cơ hội việc làm bạn vừa bỏ lỡ. Không phải vì không còn phương án nhân sự nào cho công ty đâu, chỉ vì nhà tuyển dụng thật sự đánh giá cao thái độ chuyên nghiệp và việc thể hiện bản thân đúng mực của bạn trong mọi trường hợp.

Hành trình đi tìm một công việc mơ ước có thể trải qua rất nhiều chặng đường, cả thuận lợi lẫn chông gai nhưng dù trong hoàn cảnh nào, CareerBuilder cũng xin chúc bạn luôn có cách cư xử đúng mực nhất để giữ được hình ảnh đẹp của bản thân trong mọi tình huống và hãy biết nói lời cảm ơn đến công ty “vì đã nói câu từ chối’.

Continue reading “Cảm ơn vì đã nói câu từ chối”

[Tips] Selenium – Xpath Axes

An axis defines a node-set relative to the current node.

AxisName Result
ancestor Selects all ancestors (parent, grandparent, etc.) of the current node
ancestor-or-self Selects all ancestors (parent, grandparent, etc.) of the current node and the current node itself
attribute Selects all attributes of the current node
child Selects all children of the current node
descendant Selects all descendants (children, grandchildren, etc.) of the current node
descendant-or-self Selects all descendants (children, grandchildren, etc.) of the current node and the current node itself
following Selects everything in the document after the closing tag of the current node
following-sibling Selects all siblings after the current node
namespace Selects all namespace nodes of the current node
parent Selects the parent of the current node
preceding Selects all nodes that appear before the current node in the document, except ancestors, attribute nodes and namespace nodes
preceding-sibling Selects all siblings before the current node
self Selects the current node

 

[Tip] Run successful selenium grid

When you need to config the environment to run selenium grid, your code run correctly but the browsers do not appear, you should review the following below:

1. use version stand alone 2.53 voi selenium 2.53
2. Latest Release: ChromeDriver 2.31. Supports Chrome v58-60 ok!
3. Ko Dùng port 4444 mà dùng port 9090
4. I found the solution in a bit of a convoluted way. The first step was
-. Changing the host file entry for the local host.
-. Removing the json dll from the Project References (don’t know if it has any bearing on the issue)
-. Set the IE security settings to the lowest.
-. In code, use the DesiredCapabilities.SetCapability(“ignoreProtectedModeSettings”) construct while instantiating the InterneyWebDriver object.