using javacamera2view in opencv - android

I am very new to both java and opencv especially android. From reading, I know that camera2 API support higher resolution compared to camera1 API, which is useful for my project.
I am trying to understand face-detection sample from open cv. I know that there are javacameraview and javacamera2view classes.
so far, I understand that the activity using javacameraview. however, I don't know where the javacameraview initially called. no decalaration at all.
I believe it is called in camerabridgeviewbase. but I cannot find any initialization of javacameraview.
The main goal is to replace javacameraview with javacamera2view. or use camera2 API directly.
I understand that there are some limitation in camera2 API but that is not the main problem now.
Here is the CameraBridgeViewBase initialisation
private static final String TAG = "CameraBridge";
protected static final int MAX_UNSPECIFIED = -1;
private static final int STOPPED = 0;
private static final int STARTED = 1;
private int mState = STOPPED;
private Bitmap mCacheBitmap;
private CvCameraViewListener2 mListener;
private boolean mSurfaceExist;
private final Object mSyncObject = new Object();
protected int mFrameWidth;
protected int mFrameHeight;
protected int mMaxHeight;
protected int mMaxWidth;
protected float mScale = 1;
protected int mPreviewFormat = RGBA;
protected int mCameraIndex = CAMERA_ID_ANY;
protected boolean mEnabled;
protected boolean mCameraPermissionGranted = false;
protected FpsMeter mFpsMeter = null;
public static final int CAMERA_ID_ANY = -1;
public static final int CAMERA_ID_BACK = 99;
public static final int CAMERA_ID_FRONT = 98;
public static final int RGBA = 1;
public static final int GRAY = 2;
cheers

Well iam looking in the wrong place. It is controlled in the layout. Just replace JavaCameraView with JavaCamera2View. And done. Camera2 implemented.

Related

Android: Compute color dynamically

I have a Util class which is capable of creating color codes(decimal).
public class ColorUtils {
private static final String RED = "ff0000";
private static final String GREEN = "00ff00";
private static final String BLUE = "0000ff";
private static final String WHITE = "ffffff";
private static final int RADIX = 16;
public static int getColorShade(String deepShade, String lightShade, float percentage) {
if (percentage > 100) {
throw new RuntimeException("Percentage can not be more than 100");
}
int deepShadeCode = Integer.parseInt(deepShade, RADIX);
int lightShadeCode = Integer.parseInt(lightShade, RADIX);
int shadeDifference = deepShadeCode - lightShadeCode;
int shadeOffset = (int) (shadeDifference * percentage)/100;
return lightShadeCode + shadeOffset;
}
public static int getColorShade(String deepShade, float percentage) {
return getColorShade(deepShade, WHITE, percentage);
}
public static int getRedColorShade(float percentage) {
return getColorShade(RED, percentage);
}
public static int getGreenColorShade(float percentage) {
return getColorShade(GREEN, percentage);
}
public static int getBlueColorShade(float percentage) {
return getColorShade(BLUE, percentage);
}
public static int getWhite() {
return Integer.parseInt(WHITE, RADIX);
}
}
Is there any way to convert it to Android color?
All I could find out is ContextCompat.getColor(this,R.color.yourcolor)
but this will take resource id in second arguments, I don't want to make color pallets in color.xml. Is there a work around?
Don't know how you create the color, but if it can extract red, green, blue, then try this:
#ColorInt int color = Color.rgb(getRedColorShade(percentage), getGreenColorShade(percentage), getBlueColorShade(percentage));
Ref here, this time it's pretty sure that this method is added from API level 1 and can be used instead of valueOf

what are possible arguments could be passed to getNetworkInfo()

I have checked the suggested question here, but when I checked the documentation regarding the method getNetworkInfo()here, there was no documentation regarding the possible integer values this method could handle. For an example, if I passed 0 to the getNetworkInfo() this means I am checking he mobile network, and if it is 1, I am checking the status of the WiFi.
Is there any other possible values? Why they are not in the documentation?
From the docs: http://developer.android.com/reference/android/net/ConnectivityManager.html
public static final int TYPE_NONE = -1;
public static final int TYPE_MOBILE = 0;
public static final int TYPE_WIFI = 1;
public static final int TYPE_MOBILE_MMS = 2;
public static final int TYPE_MOBILE_SUPL = 3;
public static final int TYPE_MOBILE_DUN = 4;
public static final int TYPE_MOBILE_HIPRI = 5;
public static final int TYPE_WIMAX = 6;
public static final int TYPE_BLUETOOTH = 7;
public static final int TYPE_DUMMY = 8;
public static final int TYPE_ETHERNET = 9;
public static final int TYPE_MOBILE_FOTA = 10;
public static final int TYPE_MOBILE_IMS = 11;
public static final int TYPE_MOBILE_CBS = 12;
public static final int TYPE_WIFI_P2P = 13;
public static final int TYPE_MOBILE_IA = 14;

Filling in the parameters of an Audio resampling method

I am trying to do resampling in android using this library https://github.com/intervigilium/libresample/blob/master/src/net/sourceforge/resample/Resample.java#L6
but I dont know exactly what to fill in the Parameters
I want to Resample an audio file
File mySound = new File("/mySound.wav");
to 44,100 kHz
how do i do it with this library: Library Code shown below..
package net.sourceforge.resample;
public class Resample {
public static final int DEFAULT_BUFFER_SIZE = 4096;
public static final int MAX_CHANNELS = 2;
public static final int CHANNEL_MONO = 0;
public static final int CHANNEL_LEFT = 0;
public static final int CHANNEL_RIGHT = 1;
private static final String RESAMPLE_LIB = "resample";
static {
System.loadLibrary(RESAMPLE_LIB);
}
public static native void downmix(short outputBuffer[], short inputLeft[], short inputRight[], int numSamples);
public static native int resample(double factor, short inputBuffer[], short outputBuffer[], int numSamples);
public static native void initialize(int inputRate, int outputRate, int bufferSize, int channels);
public static native double getFactor();
public static native int process(short inputBuffer[], short outputBuffer[], int channel, boolean isLast);
public static native void close();
}

How to disable unused symbologies in zbar for android paltform?

I have integrated the zbar scanner for android to my app, i only use the app to scan the qrcode, so now i want to optimize the reader by disable the unused symbologies(like PDF417 CODE39 and etc), where should i change? And i alwaye want to know what is the meaning of the number in the file Symbol.java like "QRCODE = 64" Thx:)
These are some core files:
Config.java
public class Config
{
public static final int ENABLE = 0;
public static final int ADD_CHECK = 1;
public static final int EMIT_CHECK = 2;
public static final int ASCII = 3;
public static final int MIN_LEN = 32;
public static final int MAX_LEN = 33;
public static final int UNCERTAINTY = 64;
public static final int POSITION = 128;
public static final int X_DENSITY = 400;
public static final int Y_DENSITY = 400;
}
Symbol.java
public class Symbol
{
public static final int NONE = 0;
public static final int PARTIAL = 1;
public static final int EAN8 = 8;
public static final int UPCE = 9;
public static final int ISBN10 = 10;
public static final int UPCA = 12;
public static final int EAN13 = 13;
public static final int ISBN13 = 14;
public static final int I25 = 25;
public static final int DATABAR = 34;
public static final int DATABAR_EXP = 35;
public static final int CODABAR = 38;
public static final int CODE39 = 39;
public static final int PDF417 = 57;
public static final int QRCODE = 64;
public static final int CODE93 = 93;
public static final int CODE128 = 128;
private long peer;
private int type;
private static native void init();
Symbol(long l)
{
peer = l;
}
protected void finalize()
{
destroy();
}
public synchronized void destroy()
{
if (peer != 0L)
{
destroy(peer);
peer = 0L;
}
}
private native void destroy(long l);
public int getType()
{
if (type == 0)
type = getType(peer);
return type;
}
private native int getType(long l);
public native int getConfigMask();
public native int getModifierMask();
public native String getData();
public native byte[] getDataBytes();
public native int getQuality();
public native int getCount();
public int[] getBounds()
{
int i = getLocationSize(peer);
if (i <= 0)
return null;
int ai[] = new int[4];
int j = 0x7fffffff;
int k = 0x80000000;
int l = 0x7fffffff;
int i1 = 0x80000000;
for (int j1 = 0; j1 < i; j1++)
{
int k1 = getLocationX(peer, j1);
if (j > k1)
j = k1;
if (k < k1)
k = k1;
int l1 = getLocationY(peer, j1);
if (l > l1)
l = l1;
if (i1 < l1)
i1 = l1;
}
ai[0] = j;
ai[1] = l;
ai[2] = k - j;
ai[3] = i1 - l;
return ai;
}
private native int getLocationSize(long l);
private native int getLocationX(long l, int i);
private native int getLocationY(long l, int i);
public int[] getLocationPoint(int i)
{
int ai[] = new int[2];
ai[0] = getLocationX(peer, i);
ai[1] = getLocationY(peer, i);
return ai;
}
public native int getOrientation();
public SymbolSet getComponents()
{
return new SymbolSet(getComponents(peer));
}
private native long getComponents(long l);
native long next();
static
{
System.loadLibrary("zbarjni");
init();
}
}
Modifier.java
public class Modifier
{
public static final int GS1 = 0;
public static final int AIM = 1;
public Modifier()
{
}
}
SymbolSet.java
public class SymbolSet extends AbstractCollection
{
private long peer;
private static native void init();
SymbolSet(long l)
{
peer = l;
}
protected void finalize()
{
destroy();
}
public synchronized void destroy()
{
if (peer != 0L)
{
destroy(peer);
peer = 0L;
}
}
private native void destroy(long l);
public Iterator iterator()
{
long l = firstSymbol(peer);
if (l == 0L)
return new SymbolIterator(null);
else
return new SymbolIterator(new Symbol(l));
}
public native int size();
private native long firstSymbol(long l);
static
{
System.loadLibrary("zbarjni");
init();
}
}
Like so:
scanner = new ImageScanner();
// disable all symbologies first
scanner.setConfig(0, Config.ENABLE, 0);
// only enable QRCODE
scanner.setConfig(Symbol.QRCODE, Config.ENABLE, 1);
With setConfig there are three arguments all as int's. The first is the symbol you want to affect using a Symbol static property or use 0 for all symbols. The second is the setting you want to set using a Config static property. Third is the setting value.

How to get Width and height of item in the drawable?

I am trying to declare and initialize a variable globally as final, this variable should holde thewidth and the height of an element in the drawable, how to achieve that.
I want smothing like the followinf "ofcourse it is not working, but it is roughly what i am trying to achieve:
private final int w = R.drawable.element.getwidth
You can define a function getDrawableWidth
private int getDrawableWidth(Resources resources, int id){
Bitmap bitmap = BitmapFactory.decodeResource(resources, id);
return bitmap.getWidth();
}
Then call it as below:
private final int w = getDrawableWidth(getResources(), R.drawable.element)
===Edit===
define a class to get global context(from here):
public class App extends Application{
private static Context mContext;
#Override
public void onCreate() {
super.onCreate();
mContext = this;
}
public static Context getContext(){
return mContext;
}
}
then change getDrawableWidth to another format:
private int getDrawableWidth(int id){
Bitmap bitmap = BitmapFactory.decodeResource(App.getContext().getResources(), id);
return bitmap.getWidth();
}
use it any where:
private final int w = getDrawableWidth(R.drawable.element)

Categories

Resources