achartengine: getZoomRate always returns 1.5? - android

I have a TimeChart and I'm trying to save the zoom rate whenever it is changed.
Therefore I add a ZoomListener to my chart:
public void showChart()
{
mChartView = ChartFactory.getTimeChartView(this.context, this.mDataset,
this.mRenderer, TrackedValue.DATE_FORMAT_USER);
this.layout.addView(mChartView);
mChartView.setZoomRate(prefs.getChartZoomRate());
Log.d("showChart", "Set: "+prefs.getChartZoomRate());
mChartView.addZoomListener(new ZoomListener() {
#Override
public void zoomReset() {
// TODO Auto-generated method stub
}
#Override
public void zoomApplied(ZoomEvent e) {
prefs.setChartZoomRate(e.getZoomRate());
Log.d("zoomApplied", "Save: "+String.valueOf(e.getZoomRate()+", isZoomIn: "+e.isZoomIn()));
}
}, true, true);
}
When I see the chart and press the Zoom-In button, the output of my Log is:
zoomApplied Save: 1.5, isZoomIn: true
When I zoom out (via the zoom button), the log output is:
zoomApplied Save 1.5, isZoomIn: false
No matter how often I zoom in or out, I don't get why the e.getZoomRate() always returns 1.5, no matter what the actual zoom rate is...
The e.isZoomIn() is working fine though.
Any ideas?

I have just tried the AChartEngine demo program and called the line below and it displays me the correct 1.2 value:
mChartView.setZoomRate(1.2f);
Please make sure you are setting the correct value.

Related

Using .getSpeedLimit() also makes warning sounds . How to Override?

Unable to override Here SDK to disable sound effect on the onSpeedExceeded event.
Using the Here Developer tutorial, (https://developer.here.com/blog/android-premium-sdk-speed-limit-warning-example), I succeeded in running the sample app. But...
While driving, when I exceed the speed limit, there is a doot doot doot. I want to override this behaviour as I intend to use my own sounds.
I guessed that I might override the code by creating a NavigationManager.SpeedWarningListener. Unfortunately I can not disable or defeat the 'onSpeedExceeded' sound effects.
NavigationManager.SpeedWarningListener speedWarningListener = new NavigationManager.SpeedWarningListener() {
#Override
public void onSpeedExceeded(String s, float v) {
//super.onSpeedExceeded(s, v);
//Log.v(Global.TAG, "onSpeedExceeded");
Global.SpeedLimitExceeded = true;
}
#Override
public void onSpeedExceededEnd(String s, float v) {
//super.onSpeedExceededEnd(s, v);
//Log.v(Global.TAG, "onSpeedExceededEnd");
Global.SpeedLimitExceeded = false;
}
};
EDITED ANSWER: This method needs to be amended to stop the speed warning:
private void startNavigationManager() {
NavigationManager.Error navError = NavigationManager.getInstance().startTracking();
// added by suggestion from stackoverflow
NavigationManager.getInstance().stopSpeedWarning();
if (navError != NavigationManager.Error.NONE) {
Log.d(Global.TAG, "NavigationManager: false");
//handle error navError.toString());
} else {
//Log.d(Global.TAG, "NavigationManager: true");
}
}
Please set speedWarningEnabled accordingly for NMANavigationManager
navigationManager:didUpdateSpeedingStatus:forCurrentSpeed:speedLimit: will be sent to the delegate when speeding is detected or when a correction is made.
Also refer http://developer.here.com/documentation/ios-premium/api_reference_jazzy/Classes/NMANavigationManager.html

'MyApp' has stopped and forcing to close

I'm developing Android app on Android studio using Opencv library and when I try to open my app it opens then right after that it closes and displaying crash message. I'm new on mobile development
Using : OpenCV310, Android Studio 3.0,
public class ScanLicensePlateActivity extends AppCompatActivity {
protected AnylineOcrScanView scanView;
private LicensePlateResultView licensePlateResultView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Set the flag to keep the screen on (otherwise the screen may go dark during scanning)
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.activity_anyline_ocr);
String license = getString(R.string.anyline_license_key);
// Get the view from the layout
scanView = (AnylineOcrScanView) findViewById(R.id.scan_view);
// Configure the view (cutout, the camera resolution, etc.) via json
// (can also be done in xml in the layout)
scanView.setConfig(new AnylineViewConfig(this, "license_plate_view_config.json"));
// Copies given traineddata-file to a place where the core can access it.
// This MUST be called for every traineddata file that is used
// (before startScanning() is called).
// The file must be located directly in the assets directory
// (or in tessdata/ but no other folders are allowed)
scanView.copyTrainedData("tessdata/GL-Nummernschild-Mtl7_uml.traineddata",
"8ea050e8f22ba7471df7e18c310430d8");
scanView.copyTrainedData("tessdata/Arial.traineddata", "9a5555eb6ac51c83cbb76d238028c485");
scanView.copyTrainedData("tessdata/Alte.traineddata", "f52e3822cdd5423758ba19ed75b0cc32");
scanView.copyTrainedData("tessdata/deu.traineddata", "2d5190b9b62e28fa6d17b728ca195776");
// Configure the OCR for license plate scanning via a custom script file
// This is how you could add custom scripts optimized by Anyline for your use-case
AnylineOcrConfig anylineOcrConfig = new AnylineOcrConfig();
anylineOcrConfig.setCustomCmdFile("license_plates.ale");
// set the ocr config
scanView.setAnylineOcrConfig(anylineOcrConfig);
// initialize with the license and a listener
scanView.initAnyline(license, new AnylineOcrListener() {
#Override
public void onReport(String identifier, Object value) {
// Called with interesting values, that arise during processing.
// Some possibly reported values:
//
// $brightness - the brightness of the center region of the cutout as a float value
// $confidence - the confidence, an Integer value between 0 and 100
// $thresholdedImage - the current image transformed into black and white
// $sharpness - the detected sharpness value (only reported if minSharpness > 0)
}
#Override
public boolean onTextOutlineDetected(List<PointF> list) {
// Called when the outline of a possible text is detected.
// If false is returned, the outline is drawn automatically.
return false;
}
#Override
public void onResult(AnylineOcrResult result) {
// Called when a valid result is found
String results[] = result.getText().split("-");
String licensePlate = results[1];
licensePlateResultView.setLicensePlate(licensePlate);
licensePlateResultView.setVisibility(View.VISIBLE);
}
#Override
public void onAbortRun(AnylineOcrError code, String message) {
// Is called when no result was found for the current image.
// E.g. if no text was found or the result is not valid.
}
});
// disable the reporting if set to off in preferences
if (!PreferenceManager.getDefaultSharedPreferences(this).getBoolean(
SettingsFragment.KEY_PREF_REPORTING_ON, true)) {
// The reporting of results - including the photo of a scanned meter -
// helps us in improving our product, and the customer experience.
// However, if you wish to turn off this reporting feature, you can do it like this:
scanView.setReportingEnabled(false);
}
addLicensePlateResultView();
}
private void addLicensePlateResultView() {
RelativeLayout mainLayout = (RelativeLayout) findViewById(R.id.main_layout);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
params.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
licensePlateResultView = new LicensePlateResultView(this);
licensePlateResultView.setVisibility(View.INVISIBLE);
mainLayout.addView(licensePlateResultView, params);
licensePlateResultView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startScanning();
}
});
}
private void startScanning() {
licensePlateResultView.setVisibility(View.INVISIBLE);
// this must be called in onResume, or after a result to start the scanning again
scanView.startScanning();
}
#Override
protected void onResume() {
super.onResume();
startScanning();
}
#Override
protected void onPause() {
super.onPause();
scanView.cancelScanning();
scanView.releaseCameraInBackground();
}
#Override
public void onBackPressed() {
if (licensePlateResultView.getVisibility() == View.VISIBLE) {
startScanning();
} else {
super.onBackPressed();
}
}
#Override
protected void onDestroy() {
super.onDestroy();
}}
source code is here.
If possible please help.
Logcat error shown here
Ideally more information regarding the error would be best i.e the opencv library version etc. Given it seems to be an Android issue, I would advise
File and issue or view issues pertaining to this error on their github page. Search for related Android errors to see if they match.
IF you cannot find a related error, file an issue there.

Android, Dronekit

I am develop an application for Rover to management by joystick. I need to create remote control to set direction of moving rover (left, right, forward, back). I'm trying to realize it by following code:
ControlApi.getApi(mDrone).enableManualControl(true, new ControlApi.ManualControlStateListener() {
#Override
public void onManualControlToggled(boolean b) {
}
});
ControlApi.getApi(mDrone).manualControl(0, -0.5f, 0, new AbstractCommandListener() {
#Override
public void onSuccess() {
}
#Override
public void onError(int i) {
}
#Override
public void onTimeout() {
}
});
But I'm getting an error 3 in onError block. Also before that I can't enable manual control it always return false. Can someone tell me what I'm doing wrong, or maybe guide me to the right way?
I would realy apriciate if someone can help me. Regards!
UPDATED
Still no result
Now I'm trying to use
MavLinkCommands.sendManualControl(drone, x, y, z, r, button, new ICommandListener(){...});
But can't run this method because drone is null.
I generate it like this:
MavLinkDroneManager mavLinkDroneManager =
new MavLinkDroneManager(mContext, mConnectionParameter, mHandler);
MavLinkDrone drone = mavLinkDroneManager.getDrone();
and method getDrone always return null.
SOLVED
If someone will encounter a similar problem, then the solution is quite simple. In total, you need to read the python documentation in more detail :)
All you need to do is override the channels using MAVLink command msg_rc_channels_override(); and the code with the solution will look like this:
VehicleApi.getApi(mDrone).setVehicleMode(VehicleMode.ROVER_MANUAL); //be sure the vehicle is in manual mode
VehicleApi.getApi(mDrone).arm(true); // and arm need to be true
by default chanel 1 is left-right, chanel 3 is forward-back.
If it does not work, check on the drones in which channels they are connected.
To move vehicle left set chanel 1 to 2000, right - 1000;
To move forward set chanel 3 - 2000, bacck - 1000;
I tested it on ArduRover but I think it should work with ArduPilot and ArduCopter.
msg_rc_channels_override rc_override = new msg_rc_channels_override();
rc_override.chan1_raw = 1000 //right; 2000 //left
rc_override.chan3_raw = 1000 //back; 2000 //forward
rc_override.target_system = 0;
rc_override.target_component = 0;
ExperimentalApi.getApi(mDrone).sendMavlinkMessage(new MavlinkMessageWrapper(rc_override));
For more instruction check this link

Anyline OCR SDK Integration for scanning url's in an image

I am trying to integrate anyline ocr sdk to extract url links from an image.
From their documentation I understood that by modifying the iban scanner example i can achieve the same results for an url.
Here is the config file for scan view
{
"captureResolution":"1080",
"cutout": {
"style": "rect",
"maxWidthPercent": "80%",
"maxHeightPercent": "80%",
"alignment": "top_half",
"width": 900,
"ratioFromSize": {
"width": 10,
"height": 1
},
"strokeWidth": 2,
"cornerRadius": 10,
"strokeColor": "FFFFFF",
"outerColor": "000000",
"outerAlpha": 0.3,
"feedbackStrokeColor": "0099FF"
},
"flash": {
"mode": "manual",
"alignment": "bottom_right"
},
"beepOnResult": true,
"vibrateOnResult": true,
"blinkAnimationOnResult": true,
"cancelOnResult": true,
"visualFeedback": {
"style": "contour_point",
"strokeColor": "0099FF",
"strokeWidth": 2,
"fillColor": "110099FF"
}
}
Code for ScanURLActivity.java
public class ScanURLActivity extends AppCompatActivity {
private static final String TAG = ScanURLActivity.class.getSimpleName();
private AnylineOcrScanView scanView;
private URLResultView urlResultView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Set the flag to keep the screen on (otherwise the screen may go dark during scanning)
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.activity_anyline_ocr);
addURLResultView();
String license = getString(R.string.anyline_license_key);
// Copies given traineddata-file to a place where the core can access it.
// This MUST be called for every traineddata file that is used (before startScanning() is called).
// The file must be located directly in the assets directory (or in tessdata/ but no other folders are allowed)
scanView = new AnylineOcrScanView(getApplicationContext(),null);
scanView.copyTrainedData("tessdata/eng_no_dict.traineddata", "d142032d86da1be4dbe22dce2eec18d7");
scanView.copyTrainedData("tessdata/deu.traineddata", "2d5190b9b62e28fa6d17b728ca195776");
//Configure the OCR for URLs
AnylineOcrConfig anylineOcrConfig = new AnylineOcrConfig();
// use the line mode (line length and font may vary)
anylineOcrConfig.setScanMode(AnylineOcrConfig.ScanMode.LINE);
// set the languages used for OCR
anylineOcrConfig.setTesseractLanguages("eng_no_dict", "deu");
// allow only capital letters and numbers
anylineOcrConfig.setCharWhitelist("ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz.\\:");
// set the height range the text can have
anylineOcrConfig.setMinCharHeight(20);
anylineOcrConfig.setMaxCharHeight(60);
// The minimum confidence required to return a result, a value between 0 and 100.
// (higher confidence means less likely to get a wrong result, but may be slower to get a result)
anylineOcrConfig.setMinConfidence(65);
// a simple regex for a basic validation of the URL, results that don't match this, will not be returned
// (full validation is more complex, as different countries have different formats)
anylineOcrConfig.setValidationRegex("^(?:http(s)?:\\/\\/)?[\\w.-]+(?:\\.[\\w\\.-]+)+[\\w\\-\\._~:/?#[\\]#!\\$&'\\(\\)\\*\\+,;=.]+$");
// removes small contours (helpful in this case as no letters with small artifacts are allowed, like iöäü)
anylineOcrConfig.setRemoveSmallContours(true);
// removes whitespaces from the result
// (also causes faster processing, because optimizations can be made if whitespaces are not relevant)
anylineOcrConfig.setRemoveWhitespaces(true);
// Experimental parameter to set the minimum sharpness (value between 0-100; 0 to turn sharpness detection off)
// The goal of the minimum sharpness is to avoid a time consuming ocr step,
// if the image is blurry and good results are therefor not likely.
anylineOcrConfig.setMinSharpness(66);
// set the ocr config
scanView.setAnylineOcrConfig(anylineOcrConfig);
// set an individual focus configuration for this example
FocusConfig focusConfig = new FocusConfig.Builder()
.setDefaultMode(Camera.Parameters.FOCUS_MODE_AUTO) // set default focus mode to be auto focus
.setAutoFocusInterval(8000) // set an interval of 8 seconds for auto focus
.setEnableFocusOnTouch(true) // enable focus on touch functionality
.setEnablePhaseAutoFocus(true) // enable phase focus for faster focusing on new devices
.setEnableFocusAreas(true) // enable focus areas to coincide with the cutout
.build();
// set the focus config
scanView.setFocusConfig(focusConfig);
// set the highest possible preview fps range
scanView.setUseMaxFpsRange(true);
// set sports scene mode to try and bump up the fps count even more
scanView.setSceneMode(Camera.Parameters.SCENE_MODE_SPORTS);
// initialize with the license and a listener
scanView.initAnyline(license, new AnylineOcrListener() {
#Override
public void onReport(String identifier, Object value) {
// Called with interesting values, that arise during processing.
// Some possibly reported values:
//
// $brightness - the brightness of the center region of the cutout as a float value
// $confidence - the confidence, an Integer value between 0 and 100
// $thresholdedImage - the current image transformed into black and white
// $sharpness - the detected sharpness value (only reported if minSharpness > 0)
}
#Override
public boolean onTextOutlineDetected(List<PointF> list) {
// Called when the outline of a possible text is detected.
// If false is returned, the outline is drawn automatically.
return false;
}
#Override
public void onResult(AnylineOcrResult result) {
// Called when a valid result is found (minimum confidence is exceeded and validation with regex was ok)
urlResultView.setResult(result.getText());
urlResultView.setVisibility(View.VISIBLE);
}
#Override
public void onAbortRun(AnylineOcrError code, String message) {
// Is called when no result was found for the current image.
// E.g. if no text was found or the result is not valid.
}
});
// disable the reporting if set to off in preferences
if (!PreferenceManager.getDefaultSharedPreferences(this).getBoolean(
SettingsFragment.KEY_PREF_REPORTING_ON, true)) {
// The reporting of results - including the photo of a scanned meter -
// helps us in improving our product, and the customer experience.
// However, if you wish to turn off this reporting feature, you can do it like this:
scanView.setReportingEnabled(false);
}
urlResultView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
urlResultView.setVisibility(View.INVISIBLE);
scanView.startScanning();
}
});
}
private void addURLResultView() {
RelativeLayout mainLayout = (RelativeLayout) findViewById(R.id.main_layout);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
params.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
urlResultView = new URLResultView(this);
urlResultView.setVisibility(View.INVISIBLE);
mainLayout.addView(urlResultView, params);
}
#Override
protected void onResume() {
super.onResume();
scanView.startScanning();
}
#Override
protected void onPause() {
super.onPause();
scanView.cancelScanning();
scanView.releaseCameraInBackground();
}
#Override
public void onBackPressed() {
if (urlResultView.getVisibility() == View.VISIBLE) {
urlResultView.setVisibility(View.INVISIBLE);
scanView.startScanning();
} else {
super.onBackPressed();
}
}
}
The AnylineOCRlistener is unable to detect any ocr results despite confidence set at 65.
Code for URLResultView.java class
public class URLResultView extends RelativeLayout {
private TextView resultText;
public URLResultView(Context context) {
super(context);
init();
}
public URLResultView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public URLResultView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
private void init() {
setPadding(DimensUtil.getPixFromDp(getContext(), 4), DimensUtil.getPixFromDp(getContext(), 16),
DimensUtil.getPixFromDp(getContext(), 4), DimensUtil.getPixFromDp(getContext(), 16));
//setBackgroundResource(R.drawable.);
inflate(getContext(), R.layout.url_result, this);
resultText = (TextView) findViewById(R.id.text_result);
}
public void setResult(String result) {
resultText.setText(result.trim());
}
}
Can someone help me with this integration as i am unable to find any other resource/tutorial other than their documentation and sdk samples.
Actually there are two problems that you ran into:
You only added the backslash \ to the charWhitelist, not the slash /
You have to set removeSmallContours to false
removeSmallContours removes everything from the line that is smaller than the minCharHeight. So in your case, it will remove the : and ., because they are too small for the SDK.
After changing these two settings, the scanning works fine with a minConfidence of 85.

Why the return value is not what I expected.?

The code fragment is for setting the Camera Parameters as the following:
lockRun(new Runnable() {
#Override
public void run() {
Log.v("jerikc","applyParameters before width="+getParameters().getPictureSize().width+",height="+getParameters().getPictureSize());
//preview size changed, zsd changed, camera mode changed, open camera.
mSettingChecker.applyPreferenceToParameters();
Log.v("jerikc","applyParameters after width="+getParameters().getPictureSize().width+",height="+getParameters().getPictureSize());
}
});
SettingChecker.java
public void applyPreferenceToParameters() {
Log.v("jerikc","SettingChecker.applyPreferenceToParameters before width="+mContext.getParameters().getPictureSize().width+",height="+mContext.getParameters().getPictureSize());
...
Log.v("jerikc","SettingChecker.applyPreferenceToParameters after width="+mContext.getParameters().getPictureSize().width+",height="+mContext.getParameters().getPictureSize());
}
The logs as following:
V/jerikc (17866): applyParameters before width=2560,height=android.hardware.Camera$Size#4fde180
V/jerikc (17866): SettingChecker.applyPreferenceToParameters before width=2560,height=android.hardware.Camera$Size#4fde180
V/jerikc (17866): SettingChecker.applyPreferenceToParameters after width=4096,height=android.hardware.Camera$Size#7fc9900
V/jerikc (17866): applyParameters after width=2560,height=android.hardware.Camera$Size#4fde180
I add the logs both before and end the call of
mSettingChecker.applyPreferenceToParameters() . I also add the logs
before and end inside the method applyPreferenceToParameters. The
getParameters() will return the mParameter object.
Why the values of the width are different(one is 4096, and another is
2560) ?
As you can see from the #4fde180 and #7fc9900 output at the end of your logged lines, you are using different Camera.Size objects.
Your method applyPreferenceToParameters() doesn't seem to store the changed value at the location you are expecting in the other method/class.

Categories

Resources