Java API: changing C++ vector<T> handling;
Java tests fixes are expected shortly
This commit is contained in:
@@ -1,13 +1,17 @@
|
||||
package org.opencv.samples.tutorial2;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.opencv.android.Utils;
|
||||
import org.opencv.core.Core;
|
||||
import org.opencv.core.CvVectorPoint;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.Point;
|
||||
import org.opencv.core.Scalar;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
import org.opencv.highgui.Highgui;
|
||||
import org.opencv.highgui.VideoCapture;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
@@ -18,6 +22,10 @@ class Sample2View extends SampleCvViewBase {
|
||||
private Mat mRgba;
|
||||
private Mat mGray;
|
||||
private Mat mIntermediateMat;
|
||||
private Mat mIntermediateMat2;
|
||||
private Mat mEmpty;
|
||||
private Scalar lo, hi;
|
||||
private Scalar bl, wh;
|
||||
|
||||
public Sample2View(Context context) {
|
||||
super(context);
|
||||
@@ -32,11 +40,18 @@ class Sample2View extends SampleCvViewBase {
|
||||
mGray = new Mat();
|
||||
mRgba = new Mat();
|
||||
mIntermediateMat = new Mat();
|
||||
mIntermediateMat2 = new Mat();
|
||||
mEmpty = new Mat();
|
||||
lo = new Scalar(85, 100, 30);
|
||||
hi = new Scalar(130, 255, 255);
|
||||
bl = new Scalar(0, 0, 0, 255);
|
||||
wh = new Scalar(255, 255, 255, 255);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Bitmap processFrame(VideoCapture capture) {
|
||||
/**/
|
||||
switch (Sample2NativeCamera.viewMode) {
|
||||
case Sample2NativeCamera.VIEW_MODE_GRAY:
|
||||
capture.retrieve(mGray, Highgui.CV_CAP_ANDROID_GREY_FRAME);
|
||||
@@ -44,14 +59,39 @@ class Sample2View extends SampleCvViewBase {
|
||||
break;
|
||||
case Sample2NativeCamera.VIEW_MODE_RGBA:
|
||||
capture.retrieve(mRgba, Highgui.CV_CAP_ANDROID_COLOR_FRAME_RGBA);
|
||||
Core.putText(mRgba, "OpenCV + Android", new Point(10, 100), 3/* CV_FONT_HERSHEY_COMPLEX */, 2, new Scalar(255, 0, 0, 255), 3);
|
||||
Core.putText(mRgba, "OpenCV + Android", new Point(10, 100), 3, 2, new Scalar(255, 0, 0, 255), 3);
|
||||
break;
|
||||
case Sample2NativeCamera.VIEW_MODE_CANNY:
|
||||
capture.retrieve(mGray, Highgui.CV_CAP_ANDROID_GREY_FRAME);
|
||||
/*capture.retrieve(mGray, Highgui.CV_CAP_ANDROID_GREY_FRAME);
|
||||
Imgproc.Canny(mGray, mIntermediateMat, 80, 100);
|
||||
Imgproc.cvtColor(mIntermediateMat, mRgba, Imgproc.COLOR_GRAY2BGRA, 4);
|
||||
break;
|
||||
*/
|
||||
capture.retrieve(mRgba, Highgui.CV_CAP_ANDROID_COLOR_FRAME_RGBA);
|
||||
Imgproc.cvtColor(mRgba, mIntermediateMat, Imgproc.COLOR_RGB2HSV_FULL);
|
||||
Core.inRange(mIntermediateMat, lo, hi, mIntermediateMat2); // green
|
||||
Imgproc.dilate(mIntermediateMat2, mIntermediateMat2, mEmpty);
|
||||
//
|
||||
List<CvVectorPoint> contours = new ArrayList<CvVectorPoint>();
|
||||
Mat hierarchy = new Mat();
|
||||
Imgproc.findContours(mIntermediateMat2, contours, hierarchy,Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);
|
||||
Log.d("processFrame", "contours.size()" + contours.size());
|
||||
double maxArea = 0;
|
||||
int indexMaxArea = -1;
|
||||
for (int i = 0; i < contours.size(); i++) {
|
||||
double s = Imgproc.contourArea(contours.get(i));
|
||||
if(s > maxArea){
|
||||
indexMaxArea = i;
|
||||
maxArea = s;
|
||||
}
|
||||
}
|
||||
|
||||
mRgba.setTo(bl);
|
||||
Imgproc.drawContours(mRgba, contours, indexMaxArea, wh);
|
||||
//
|
||||
//Imgproc.cvtColor(mIntermediateMat2, mRgba, Imgproc.COLOR_GRAY2RGBA);
|
||||
break;
|
||||
}
|
||||
/**/
|
||||
|
||||
Bitmap bmp = Bitmap.createBitmap(mRgba.cols(), mRgba.rows(), Bitmap.Config.ARGB_8888);
|
||||
|
||||
@@ -78,6 +118,9 @@ class Sample2View extends SampleCvViewBase {
|
||||
if (mIntermediateMat != null)
|
||||
mIntermediateMat.release();
|
||||
|
||||
if (mIntermediateMat2 != null)
|
||||
mIntermediateMat2.release();
|
||||
|
||||
mRgba = null;
|
||||
mGray = null;
|
||||
mIntermediateMat = null;
|
||||
|
Reference in New Issue
Block a user