Skip to content

Commit

Permalink
updated opencv to 3.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ravindu committed Aug 11, 2017
1 parent 0bc059f commit 5ec99db
Show file tree
Hide file tree
Showing 149 changed files with 22,381 additions and 33,630 deletions.
3 changes: 3 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

81 changes: 60 additions & 21 deletions app/src/main/java/com/rw/imagingsample/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,18 @@
import android.os.Bundle;
import android.util.Log;
import android.view.TextureView;
import android.view.View;

import com.rw.imaging.CameraController;
import com.rw.imaging.ImagingUtils;
import com.rw.imagingsample.databinding.ActivityMainBinding;

import org.opencv.android.Utils;
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.imgproc.Imgproc;

public class MainActivity extends AppCompatActivity implements CameraController.PreviewCallback
{
private ActivityMainBinding mBinding;
Expand All @@ -28,6 +35,26 @@ protected void onCreate(Bundle savedInstanceState)

mBinding = DataBindingUtil.setContentView(this, R.layout.activity_main);

mBinding.frontCam.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
stopCamera();
startCamera(CameraController.CameraType.Front, 90);
}
});

mBinding.backCam.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
stopCamera();
startCamera(CameraController.CameraType.Default, 90);
}
});

}

@Override
Expand All @@ -41,40 +68,54 @@ protected void onResume()
}
else
{
startCamera();
startCamera(CameraController.CameraType.Front, 90);
}
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults)
{
super.onRequestPermissionsResult(requestCode, permissions, grantResults);

if(grantResults[0] == PackageManager.PERMISSION_GRANTED)
startCamera();
}
// @Override
// public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults)
// {
// super.onRequestPermissionsResult(requestCode, permissions, grantResults);
//
// if(grantResults[0] == PackageManager.PERMISSION_GRANTED)
// startCamera();
// }

@SuppressWarnings("MissingPermission")
private void startCamera()
private void startCamera(CameraController.CameraType type, int rotation)
{
CameraController.connect(CameraController.CameraType.Front, 90);
Log.d("IMG", "opencv version: " + ImagingUtils.getVersion());

if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED)
{
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, 1);
}
else
{
CameraController.connect(type, rotation);

CameraController.PreviewSize p = new CameraController.PreviewSize(640, 480);// CameraController.getBestPreviewSize(640, 480);
CameraController.PreviewSize p = new CameraController.PreviewSize(640, 480);// CameraController.getBestPreviewSize(640, 480);

Log.d("IMG", "best preview: " + p.width+"x"+p.width);
Log.d("IMG", "best preview: " + p.width + "x" + p.width);

CameraController.setPreviewCallback(this);
CameraController.setPreviewCallback(this);

CameraController.startPreview(mBinding.previewMain, p);
}
}

CameraController.startPreview(mBinding.previewMain, p);
private void stopCamera()
{
CameraController.stopPreview();
CameraController.disconnect();
}

@Override
protected void onPause()
{
super.onPause();

CameraController.stopPreview();
CameraController.disconnect();
stopCamera();
}

@Override
Expand All @@ -85,17 +126,15 @@ public void onCameraFrame(byte[] frame, CameraController.PreviewSize previewSize
long t = System.currentTimeMillis();

ImagingUtils.PreviewResizeParams p = new ImagingUtils.PreviewResizeParams.Builder()
// .setTargetSize(c.getWidth(), c.getHeight())
.setTargetSize(c.getWidth(), c.getHeight())
.setBounds(0, (previewSize.width-previewSize.height)/2, previewSize.height, previewSize.width - (previewSize.width-previewSize.height)/2)
.setRotation(ImagingUtils.PreviewResizeParams.Rotation.Clockwise_90)
.create();

Bitmap b = ImagingUtils.rotateCropAndResizePreview(frame, previewSize.width, previewSize.height, p);
c.drawBitmap(b, 0, 0, null);


c.drawBitmap(b, new Rect(0, 0, b.getWidth(), b.getHeight()), new Rect(0, 0, c.getWidth(), c.getHeight()), null);
// c.drawBitmap(b, 0, 0, null);

Log.d("IMG", "processing time: " + (System.currentTimeMillis() - t));

mBinding.previewCustom.unlockCanvasAndPost(c);
Expand Down
19 changes: 19 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,24 @@
app:layout_constraintLeft_toLeftOf="@+id/preview_custom"
app:layout_constraintRight_toRightOf="@+id/preview_custom"
app:layout_constraintTop_toBottomOf="@+id/preview_custom"/>

<Button
android:id="@+id/front_cam"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:text="front"
app:layout_constraintBottom_toBottomOf="parent"
tools:layout_editor_absoluteX="15dp"/>

<Button
android:id="@+id/back_cam"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="0dp"
android:layout_marginLeft="16dp"
android:text="back"
app:layout_constraintBottom_toBottomOf="@+id/front_cam"
app:layout_constraintLeft_toRightOf="@+id/front_cam"/>
</android.support.constraint.ConstraintLayout>
</layout>
6 changes: 3 additions & 3 deletions imaging-utils/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.opencv"
android:versionCode="24133"
android:versionName="2.4.13.3">
android:versionCode="3300"
android:versionName="3.3.0">

<uses-sdk android:minSdkVersion="8" />
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="21" />
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public void install()
}
public void cancel()
{
Log.d(TAG, "Wating for OpenCV canceled by user");
Log.d(TAG, "Waiting for OpenCV canceled by user");
mServiceInstallationProgress = false;
int Status = LoaderCallbackInterface.INSTALL_CANCELED;
Log.d(TAG, "Init finished with status " + Status);
Expand Down Expand Up @@ -197,7 +197,7 @@ public void install() {
if (mEngineService.installVersion(mOpenCVersion))
{
mLibraryInstallationProgress = true;
Log.d(TAG, "Package installation statred");
Log.d(TAG, "Package installation started");
Log.d(TAG, "Unbind from service");
mAppContext.unbindService(mServiceConnection);
}
Expand Down Expand Up @@ -228,7 +228,7 @@ public void cancel() {
mUserAppCallback.onManagerConnected(LoaderCallbackInterface.INSTALL_CANCELED);
}
public void wait_install() {
Log.e(TAG, "Instalation was not started! Nothing to wait!");
Log.e(TAG, "Installation was not started! Nothing to wait!");
}
};

Expand Down Expand Up @@ -376,7 +376,7 @@ private boolean initOpenCVLibs(String Path, String Libs)
else
{
// If the dependencies list is not defined or empty.
String AbsLibraryPath = Path + File.separator + "libopencv_java.so";
String AbsLibraryPath = Path + File.separator + "libopencv_java3.so";
result &= loadLibrary(AbsLibraryPath);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void onClick(DialogInterface dialog, int which) {
/** Package installation has been canceled. **/
case LoaderCallbackInterface.INSTALL_CANCELED:
{
Log.d(TAG, "OpenCV library instalation was canceled by user");
Log.d(TAG, "OpenCV library installation was canceled by user");
finish();
} break;
/** Application is incompatible with this version of OpenCV Manager. Possibly, a service update is required. **/
Expand Down
Loading

0 comments on commit 5ec99db

Please sign in to comment.