The shift of the x-axis marks achartengine barchart compared to the values - achartengine

I am new to writing apps. I created a BarChart using aChartEngine for my Android app. I cannot set the labels in the center for the x-axis in my chart.
private void initChart() {
mCurrentSeries = new XYSeries("");
mDataset.addSeries(mCurrentSeries);
XYSeriesRenderer mCurrentRenderer = new
XYSeriesRenderer();
mCurrentRenderer.setChartValuesTextSize(20);
mCurrentRenderer.setColor(Color.BLACK);
mCurrentRenderer.setChartValuesTextAlign(Paint.Align.CENTER);
mCurrentRenderer.setFillPoints(false);
mCurrentRenderer.setLineWidth(5);
mCurrentRenderer.setDisplayChartValues(true);
mCurrentSeries2 = new XYSeries("");
mDataset.addSeries(mCurrentSeries2);
XYSeriesRenderer mCurrentRendererRed = new
XYSeriesRenderer();
mCurrentRendererRed.setChartValuesTextSize(20);
mCurrentRendererRed.setColor(Color.RED);
mCurrentRendererRed.setChartValuesTextAlign(Paint.Align.CENTER);
// mCurrentRendererRed.setFillPoints(false);
mCurrentRendererRed.setLineWidth(5);
mCurrentRendererRed.setDisplayChartValues(true);
mRenderer.addSeriesRenderer(mCurrentRenderer);
mRenderer.addSeriesRenderer(mCurrentRendererRed);
mRenderer.setBarSpacing(1);
mRenderer.setXLabels(9);
mRenderer.setYLabels(30);
mRenderer.setXAxisMin(0);
mRenderer.setXAxisMax(17);
mRenderer.setYAxisMin(2);
mRenderer.setYAxisMax(4);
mRenderer.setLabelsTextSize(30);
mRenderer.setYLabelsColor(0,Color.RED);
mRenderer.setXLabelsColor(Color.RED);
mRenderer.setYAxisAlign(Paint.Align.LEFT, 0);
mRenderer.setYLabelsAlign(Paint.Align.RIGHT, 0);
mRenderer.setShowGridY(true);
mRenderer.setShowGridX(true);
mRenderer.setApplyBackgroundColor(true);
mRenderer.setMarginsColor(Color.WHITE);
mRenderer.setMargins(new int[] {0, 50, 0, 50});
mRenderer.setBarSpacing(0.15);
mRenderer.setZoomEnabled(true);
mRenderer.setZoomButtonsVisible(true);
mRenderer.setClickEnabled(true);
mRenderer.setShowLegend(false);
}
that's what happened [https://i.stack.imgur.com/VWRuT.png]

Related

three.js, dat.GUI slider controlled by code, morph targets do not move

I work on a human face that the mouth should move about external coordinates (OpenCV and dlibs). In a first step I try to control the dat.GUI by code, which already works. But now I have the problem that the morph targets do not move when I control by code. The sliders move, but the face doesn't. When I use the mouse, they work perfectly. I ask for help with this problem.
<script>
// Laden der 3DScene
var scene = new THREE.Scene();
// Laden der Kamear Perspektive
var camera = new THREE.PerspectiveCamera(15, window.innerWidth/window.innerHeight, 1, 10000);
camera.position.z = 17;
camera.position.y = 3;
// Laden des Renderers
var renderer = new THREE.WebGLRenderer({ alpha: false });
renderer.setClearColor( 0x000000 );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// Laden des Orbitcontrollers
var controls = new THREE.OrbitControls( camera, renderer.domElement );
// Laden der Lichter (Beleuchtung)
var ambientLight = new THREE.AmbientLight(0x111111);
scene.add(ambientLight);
var light = new THREE.PointLight( 0xFFFFDD );
light.position.set( -15, 10, 15 );
scene.add(light);
// Laden des Json Modells
var loader = new THREE.JSONLoader();
loader.load( "./three/models/JSON/test/mkh_shapes.json", function (geometry) {
var material = new THREE.MeshLambertMaterial({morphTargets: true});
var mesh = new THREE.Mesh(geometry, material);
mesh.scale.set(1.2,1.2,1.2); //Modellgrösse die angezeigt wird
mesh.position.x = 0; //Position (x = nach rechts+ links-)
mesh.position.y = -19; //Position (y = nach oben +, unten-)
mesh.position.z = 0; //Position (z = nach vorne +, hinten-)
scene.add(mesh);
//dat.Gui
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var shape = {
mouth_open: 0.0, //Anfangsposition 0.0
};
var gui = new dat.GUI();
var folder = gui.addFolder( 'Morph Targets' );
folder.add( shape, 'mouth_open', 0, 1 ).step( 0.01 ).name('mouth_open').listen().onChange ( function( a ) { mesh.morphTargetInfluences[ 40 ] = a;} );
folder.open();
var updateGui = function() {
for (var i in folder.__controllers) {
folder.__controllers[i].updateDisplay();
}
}
var time = Date.now() * 0.003;
shape.mouth_open = 0.50 //* Math.sin( 0.5 * time ) + 0.3;
//scene.add(shape);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
});
function animate() {
render();
requestAnimationFrame( animate );
}
function render() {
renderer.clear();
renderer.render( scene, camera );
}
animate();
</script>
I have made my own version with extra features like :
Gui auto resize based on content div.
Improved slidecontroller as unique controller (slide or number insert);
Multi language automatic support
Auto check for conflicts in options, then ask for confirm or cancel.
Auto Show/hide other controllers when option selected deselected (example show color list only if "custom color is selected")
ecc.. ecc..
here is the Video
Now is more confortable and easy to use.

NSAttributedString using NSSuperscriptAttributeName in Xamarin iOS

Hi Im trying to get the superscript attribute to work with a UILabel in a xamarin iOS app. I have the following code, Im using a sketches right now just to see how it looks, so should be easy to copy/paste :D :
using UIKit;
using Foundation;
using CoreGraphics;
var label = new UILabel( new CGRect(0,0,UIScreen.MainScreen.Bounds.Width, UIScreen.MainScreen.Bounds.Height));
label.Text = "100.0o";
label.TextAlignment = UITextAlignment.Center;
var prettyString = new NSMutableAttributedString ("UITextField is not pretty!");
prettyString.AddAttribute (UIStringAttributeKey.SuperscriptAttributeName, NSNumber.FromDouble (1.0), new NSRange (prettyString.Length -1 , 1));
label.AttributedText = prettyString;
RootView.Add(label);
I can see from here that it is available in MonoMac.Foundation. Does anyone know how to get that string in iOS as it doesn't seem to be available from UIKit.UIStringAttributeKey.
From this answer I was able to use UIStringAttributeKey.BaselineOffset like so:
// Sketch your next great idea!
using UIKit;
using Foundation;
using CoreGraphics;
using CoreText;
var slider = new UISlider (new CGRect(0,UIScreen.MainScreen.Bounds.Height-30,UIScreen.MainScreen.Bounds.Width, 30.0f));
slider.MinValue = 10.0f;
slider.MaxValue = 120.0f;
var h = 65.0f;
var label = new UILabel( new CGRect(0,h,UIScreen.MainScreen.Bounds.Width, h*2));
var firstAttributes = new UIStringAttributes ();
var secondAttributes = new UIStringAttributes ();
var prettyString = new NSMutableAttributedString ("99.99°");
var label2 = new UILabel( new CGRect(0,h*3,UIScreen.MainScreen.Bounds.Width, h));
slider.ValueChanged += (object sender, EventArgs e) =>
{
h = slider.Value;
label.Text = slider.Value.ToString ();
label.Frame = new CGRect(0,h,UIScreen.MainScreen.Bounds.Width, h*2);
label.TextAlignment = UITextAlignment.Center;
label.Font = UIFont.FromName("Helvetica", h);
firstAttributes = new UIStringAttributes (new NSDictionary(
// Can set this to >1.0 to make it higher but was too high for me.
// CTStringAttributeKey.Superscript, NSNumber.FromDouble (0.0),
UIStringAttributeKey.Font ,UIFont.FromName("Helvetica", h),
UIStringAttributeKey.BackgroundColor ,UIColor.FromRGBA (0.0f, 1.0f, 1.0f, 0.2f)
));
secondAttributes = new UIStringAttributes (new NSDictionary(
UIStringAttributeKey.Font ,UIFont.FromName("Helvetica", h/2),
UIStringAttributeKey.BackgroundColor ,UIColor.FromRGBA (1.0f, 0.0f, 1.0f, 0.2f),
UIStringAttributeKey.BaselineOffset, NSNumber.FromDouble (h/3)
));
prettyString.SetAttributes (firstAttributes.Dictionary, new NSRange (1, prettyString.Length-1));
prettyString.SetAttributes (secondAttributes.Dictionary, new NSRange (prettyString.Length-1, 1));
label.AttributedText = prettyString;
label2.Frame = new CGRect(0,h*3,UIScreen.MainScreen.Bounds.Width, h);
label2.Text = "99.99°";
label2.TextAlignment = UITextAlignment.Center;
label2.Font = UIFont.FromName("Helvetica", h);
};
RootView.Add(slider);
RootView.Add(label);
RootView.Add(label2);

How to write to file (encode) modified camera frames in Windows Phone 8

I have custom an camera app in Windows Phone 8. I need add a watermark image to each frame from camera capture and then record to a video.
I can customise each frame from the preview using the following code:
int[] pixelData = new int[(int)(camera.PreviewResolution.Width * camera.PreviewResolution.Height)];
camera.GetPreviewBufferArgb32(pixelData);
return pixelData;
and write it back to the preview.
my problem is that while I can show the frames on the screen while the user is recording a movie using the camera I cant find a working solution for WP8 to encode the frames and audio to save to a file.
I already tried opencv,libav and others without success,
if anyone can point me to the right direction it would be greatly appreciated.
You can do it like this.
private void GetCameraPicture_Click(object sender, RoutedEventArgs e)
{
Microsoft.Phone.Tasks.CameraCaptureTask cameraCaptureTask = new Microsoft.Phone.Tasks.CameraCaptureTask();
cameraCaptureTask.Completed += cct_Completed;
cameraCaptureTask.Show();
}
try
{
if (e.TaskResult == Microsoft.Phone.Tasks.TaskResult.OK)
{
var imageStream = e.ChosenPhoto;
var name = e.OriginalFileName;
using (MemoryStream mem = new MemoryStream())
{
TextBlock tb = new TextBlock() { Text = DateTime.Now.ToString("dd MMM yyyy, HH:mm"), Foreground = new SolidColorBrush(Color.FromArgb(128, 0, 0, 0)), FontSize = 40 };
BitmapImage finalImage = new BitmapImage();
finalImage.SetSource(imageStream);
WriteableBitmap wbFinal = new WriteableBitmap(finalImage);
wbFinal.Render(tb, null);
wbFinal.Invalidate();
wbFinal.SaveJpeg(mem, wbFinal.PixelWidth, wbFinal.PixelHeight, 0, 100);
mem.Seek(0, System.IO.SeekOrigin.Begin);
MediaLibrary lib = new MediaLibrary();
lib.SavePictureToCameraRoll("Copy" + name, mem.ToArray());
}
}
}
catch (Exception exp) { MessageBox.Show(exp.Message); }
Hope it may help you.

Why is the CvBlobDetector in openCV in the legacy lib?

Is there a newer blob detection/tracking library?
Is it not a good library?
Isn't legacy supposed to be old and not useful code?
Does anybody know?
Here is newer blob detector:
http://opencv.itseez.com/modules/features2d/doc/common_interfaces_of_feature_detectors.html#SimpleBlobDetector
Here is my code which i used to track the blob in Emgucv 3.1 Version
//MCvFont font = new MCvFont(Emgu.CV.CvEnum.FontFace.HersheySimplex, 0.5, 0.5);
using (CvTracks tracks = new CvTracks())
using (ImageViewer viewer = new ImageViewer())
using (Capture capture = new Capture())
using (Mat fgMask = new Mat())
{
//BGStatModel<Bgr> bgModel = new BGStatModel<Bgr>(capture.QueryFrame(), Emgu.CV.CvEnum.BG_STAT_TYPE.GAUSSIAN_BG_MODEL);
BackgroundSubtractorMOG2 bgModel = new BackgroundSubtractorMOG2(0, 0, true);
//BackgroundSubstractorMOG bgModel = new BackgroundSubstractorMOG(0, 0, 0, 0);
capture.ImageGrabbed += delegate(object sender, EventArgs e)
{
Mat frame = new Mat();
capture.Retrieve(frame);
bgModel.Apply(frame, fgMask);
using (CvBlobDetector detector = new CvBlobDetector())
using (CvBlobs blobs = new CvBlobs())
{
detector.Detect(fgMask.ToImage<Gray, Byte>(), blobs);
blobs.FilterByArea(100, int.MaxValue);
tracks.Update(blobs, 20.0, 10, 0);
Image<Bgr, Byte> result = new Image<Bgr, byte>(frame.Size);
using (Image<Gray, Byte> blobMask = detector.DrawBlobsMask(blobs))
{
frame.CopyTo(result, blobMask);
}
//CvInvoke.cvCopy(frame, result, blobMask);
foreach (KeyValuePair<uint, CvTrack> pair in tracks)
{
if (pair.Value.Inactive == 0) //only draw the active tracks.
{
CvBlob b = blobs[pair.Value.BlobLabel];
Bgr color = detector.MeanColor(b, frame.ToImage<Bgr, Byte>());
result.Draw(pair.Key.ToString(), pair.Value.BoundingBox.Location, Emgu.CV.CvEnum.FontFace.HersheySimplex, 0.5, color);
result.Draw(pair.Value.BoundingBox, color, 2);
Point[] contour = b.GetContour();
result.Draw(contour, new Bgr(0, 0, 255), 1);
}
}
viewer.Image = frame.ToImage<Bgr, Byte>().ConcateVertical(fgMask.ToImage<Bgr, Byte>().ConcateHorizontal(result));
}
};
capture.Start();
viewer.ShowDialog();
}

Scaling multiple axes in PlotChart

When I programmatically create a PlotChart starting w/ no series and adding series w/ own scaling and verticalAxes (and Renderers but not necessary for behavior error), the axes and data show, but the default axis controls all scaling and the other axes are erroneous. Thus, the yValue magnitudes do not correspond to their associated axes and mixing series w/ grossly different orders of magnitude squishes all but the largest into indistinguishable floor values. I cannot null out the default vertical axis as it gets an null pointer error. [Click anywhere on the chart to add the next series.]
package
{
/*
* Attempt to dynamically create graph w/ varying series. Having difficulty getting axis to render correctly based
* on sets of series. Having trouble getting more than one series. I can't munge the yValue property because in my
* actual code all of the data elements are instances of the same class with properties akin to series, xValue, and yValue.
*
*/
import flash.events.MouseEvent;
import mx.charts.AxisRenderer;
import mx.charts.DateTimeAxis;
import mx.charts.LinearAxis;
import mx.charts.PlotChart;
import mx.charts.chartClasses.Series;
import mx.charts.events.ChartEvent;
import mx.charts.series.PlotSeries;
import mx.collections.ArrayCollection;
public class GraphSample extends PlotChart
{
public function GraphSample()
{
super();
this.selectionMode = "single";
this.percentWidth = 80;
this.series = new Array();
this.verticalAxisRenderers = new Array();
this.showDataTips = true;
}
protected override function createChildren():void {
super.createChildren();
// Create the horizontal axis
var hAxis:DateTimeAxis = new DateTimeAxis();
hAxis.dataUnits = "days";
this.horizontalAxis = hAxis;
// NOTE: I do not want an automatically created verticalAxis, but can't seem to avoid it
// Add vertical axis renderer
var axis:AxisRenderer = new AxisRenderer();
axis.axis = this.verticalAxis;
axis.horizontal = false;
axis.setStyle("showLabels", true);
axis.setStyle("showLine", true);
this.verticalAxisRenderers.push(axis);
this.verticalAxisRenderers = this.verticalAxisRenderers;
this.addEventListener(ChartEvent.CHART_CLICK, addSeries);
}
private var seriesColors:Array = [0x888888, 0xFFC833, 0xFF6433, 0xE73399,
0x8133CC, 0x346B9B, 0x33C399, 0x98F133];
private var seriesColorCursor:int = 0;
private const ONE_DAY:Number = (1000 * 60 * 60 * 24);
private const TODAY:Date = new Date();
private function addSeries(event:MouseEvent):void {
var dimension:Object = newDimension();
var series:Series = new PlotSeries();
series.displayName = dimension.name;
series.dataFunction = genericFieldRetriever;
series.setStyle("fill", seriesColors[seriesColorCursor++]);
if (seriesColorCursor > seriesColors.length) seriesColorCursor %= seriesColors.length;
series.dataProvider = dimension.elements;
this.series.push(series);
var seriesAxis:LinearAxis = new LinearAxis();
series.setAxis("verticalAxis", seriesAxis);
var min:Number = Number.MAX_VALUE, max:Number = 0;
for each (var ele:Object in series.dataProvider) {
if (ele.value > max) max = ele.value;
if (ele.value < min) min = ele.value;
}
seriesAxis.minimum = min * 0.85;
seriesAxis.maximum = max * 1.2;
seriesAxis.displayName = series.displayName;
seriesAxis.title = series.displayName;
// Add vertical axis renderer
var axis:AxisRenderer = new AxisRenderer();
axis.axis = seriesAxis;
axis.horizontal = false;
axis.setStyle("color", series.getStyle("fill"));
axis.setStyle("showLabels", true);
axis.setStyle("showLine", true);
this.verticalAxisRenderers.push(axis);
this.verticalAxisRenderers = this.verticalAxisRenderers;
// also strokes?
// http://www.flexdeveloper.eu/forums/flex-charting/creating-linecolumn-series-dynamically/
this.series = this.series;
this.invalidateSeriesStyles();
if (names.length == 0) this.removeEventListener(ChartEvent.CHART_CLICK, addSeries);
}
/**
* A fake of the server data retrieval mechanism.
* #return wrapper w/ name and elements set where each element has a data and value.
*/
private function newDimension():Object {
var result:Object = new Object();
result['name'] = names.shift();
var elements:ArrayCollection = new ArrayCollection();
var thisBase:int = base.shift();
var thisMax:int = maxAdd.shift();
for (var date:Date = new Date(TODAY.getTime() - 10 * ONE_DAY); date.getTime() <= TODAY.getTime(); date = new Date(date.getTime() + ONE_DAY)) {
var element:Object = new Object();
element['date'] = date;
element['value'] = thisBase + Math.random() * thisMax;
elements.addItem(element);
}
result['elements'] = elements;
return result;
}
private var names:Array = ['fat', 'carbs', 'steps', 'walking miles', 'pounds', 'cycling miles', 'running miles', 'skiing hours', 'lifting mins'];
private var base:Array = [0, 20, 1000, 0, 100, 0, 0, 0, 0];
private var maxAdd:Array = [100, 200, 9000, 4, 200, 40, 8, 3, 75];
private function genericFieldRetriever(series:Series, item:Object, fieldName:String):Object {
if(fieldName == 'yValue')
return(item.value);
else if(fieldName == "xValue")
return(item.date);
else
return null;
}
}
}
The problem was the line
series.setAxis("verticalAxis", seriesAxis);
That is not equivalent to
series.verticalAxis = seriesAxis;
Once I changed that, everything works perfectly, but it cannot handle the abstract Series class b/c that class does not have the setter for verticalAxis.

Resources