Find the co-ordinates of matching image using sikuli in java - sikuli

I need to get the co-ordinates of matched image within the actualImage so that I can perform operations on it. However, I tried below two approaches,but both doesn't seem to work:
Approach 1:
Using below, I'm able to find a match but co-ordinates returned are just the width & height of image to be matched(which I already know). I want to get the position of the same within actual image.
BufferedImage actualImg = ImageIO.read(new File("C:/Images/SrcImg.PNG"));
ImageTarget actualTgt = new ImageTarget(actualImg);
BufferedImage searchImg = ImageIO.read(new File("C:/Images/TgtImg.PNG"));
ImageTarget searchTgt = new ImageTarget(searchImg);
ScreenRegion scrReg = new StaticImageScreenRegion(actualTgt.getImage());
ScreenRegion resReg = scrReg.find(searchTgt);
ScreenLocation center = resReg.getCenter();
System.out.println(":getElementFromImage: x_loc,y_loc =["+center.getX()+","+center.getY()+"]");
Approach 2:
In below code I tried with sikulix Finder. However, with this src.hasNext() returned true BUT src.next() threw nullpointer exception.Not sure what is the problem here:
Finder src = new Finder("C:/Images/SrcImg.PNG");
Pattern pat = new Pattern("C:/Images/TgtImg.PNG").similar(0.5);
src.find(pat);
Match m;
while( src.hasNext())
m = src.next();
src.destroy();
java.lang.NullPointerException
at org.sikuli.script.Finder.next(Finder.java:484)
at com.work.ImageFinder.main(ImageFinder.java:38)
I already spent good amount of time to make this work. Any help would be much appreciated.
Thanks!

It works fine after passing the Region to Finder like below:
Finder src = new Finder("C:/Images/SrcImg.PNG", new Region(0,0,<width>,<height>))
Pattern pat = new Pattern("C:/Images/TgtImg.PNG").similar(0.5);
src.find(pat);
Match m;
while( src.hasNext())
m = src.next();
src.destroy();
More details can be found below link:
Is it possible to use Sikuli to assert that images are the same in GUI-less mode?

Related

Oxyplot showing HeatMapSeries behind ScatterSeries

I am trying to combine LineSeries, ScatterSeries and HeatmapSeries on a single OxyPlot instance. I am able to show the first two just fine on the same plot and it looks like the following:
The axes for this are generated by the following code:
var xAxis = new DateTimeAxis();
xAxis.Key = "X";
xAxis.Position = AxisPosition.Bottom;
xAxis.AbsoluteMinimum = DateTimeAxis.ToDouble(CurrentPass.AOS);
xAxis.AbsoluteMaximum = DateTimeAxis.ToDouble(CurrentPass.LOS);
xAxis.AxislineColor = xAxis.TextColor = xAxis.TicklineColor = xAxis.MajorGridlineColor = OxyColors.DarkGray;
var yAxis = new LinearAxis();
yAxis.Key = "Y";
yAxis.Position = AxisPosition.Left;
yAxis.AbsoluteMinimum = 0.0;
yAxis.AbsoluteMaximum = MaximumFrequency;
yAxis.Maximum = MaximumFrequency;
yAxis.AxislineColor = yAxis.TextColor = yAxis.TicklineColor = yAxis.MajorGridlineColor = OxyColors.DarkGray;
If I add in a third axes for the Heatmap (not even a HeatMapSeries yet), I get the following:
The extra code here for the axis for the HeatMap is:
var heatmapAxis = new LinearColorAxis();
heatmapAxis.AbsoluteMinimum = 0.0;
heatmapAxis.AbsoluteMaximum = MaximumFrequency;
heatmapAxis.Palette = OxyPalettes.Gray(1024);
heatmapAxis.Key = "HeatMap";
I am not sure what's going on here. The line series still shows. And all the ScatterPoints from the scatterseries I have are definitely there - the tracker shows up and I can interact with the points (hover, click etc.). But the points don't show. If I add a HeatMapSeries, the HeatMapSeries data does show up as expected, the LineSeries data still shows up but no ScatterSeries data.
Again, the HeatMap data and the Scatter Series data show up individually, but never together.
Has anyone encountered this before? Are there workarounds?
Thanks,
Aditya
Sorry this is a bit late but just stumbled upon this. I had something similar with a line not showing up on a Heatmap and after some experimenting i realized the order in which the series' are added to the plot model make a big difference. Make sure you add your ScatterSeries after you've added your Heatmap to the plot model.

Particle Effect Changing Color at runtime

I need to change color of my particle effect color according to some user event in my game for that this is what i am doing:
float temp[] = new float[4];
temp[0] = 0.937f;
temp[1] = 0.325f;
temp[2] = 0.314f;
pe.getEmitters().first().getTint().setColors(temp);
pe.start();
and in render i am doing this:
pe.draw(batch, Gdx.graphics.getDeltaTime());
but unfortunately i am getting this error:
java.lang.ArrayIndexOutOfBoundsException: length=4; index=4
at com.badlogic.gdx.graphics.g2d.ParticleEmitter$GradientColorValue.getColor(ParticleEmitter.java:1313)
at com.badlogic.gdx.graphics.g2d.ParticleEmitter.activateParticle(ParticleEmitter.java:439)
at com.badlogic.gdx.graphics.g2d.ParticleEmitter.addParticle(ParticleEmitter.java:154)
at com.badlogic.gdx.graphics.g2d.ParticleEmitter.draw(ParticleEmitter.java:299)
at com.badlogic.gdx.graphics.g2d.ParticleEffect.draw(ParticleEffect.java:74)
at com.approduction.game.GameScreen.render(GameScreen.java:218)
at com.badlogic.gdx.Game.render(Game.java:46)
at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:459)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1557)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1263)
i dont know what i am doing wrong, i read the documentation and has done everything according to it any help would be a savior... Thanks in advance..
Your float array has the wrong length.
You actually don't need to create a new array. You can avoid this problem altogether by filling your colors into the array it already has like this:
float temp[] = pe.getEmitters().first().getTint().getColors();
temp[0] = 0.937f;
temp[1] = 0.325f;
temp[2] = 0.314f;
pe.start();

Masked images not displaying in AS3

I am trying to mask an image on another so that I only view the specific portion of the unmasked image through the masked one. My problem is that I cannot see anything on the screen.. no Image, no effect at all
cardMask = new Image(Root.assets.getTexture("card_mask"));
cardMask.y = Constants.STAGE_HEIGHT*0.40;
cardMask.x = Constants.STAGE_WIDTH *0.48;
trace("it's add mask");
cardLight = new Image(Root.assets.getTexture("card_light_mask"));
cardLight.y = Constants.STAGE_HEIGHT*0.46;
cardLight.x = Constants.STAGE_WIDTH *0.48;
cardLight.mask=cardMask;
maskedDisplayObject = new PixelMaskDisplayObject(-1,false);
maskedDisplayObject.addChild(cardLight);
maskedDisplayObject.x=cardLight.x;
maskedDisplayObject.y=cardLight.y;
maskedDisplayObject.mask=cardMask;
maskedDisplayObject.blendMode = BlendMode.SCREEN;
addChild(maskedDisplayObject);
First, for masking an object the mask object should also be added to the display list. Your code does not add cardMask to display list anywhere. Second, if your maskedDisplayObject should be visible at all times, the mask should be assigned not to it, but to some other object which displayed part you desire to control. And third, it is also possible that this.stage is null, therefore the entire tree (this -> maskedDisplayObject -> cardLight) is plain not rendered. You need to check all three of these conditions to get something displayed.
Also, if you desire cardLight as an object to move independently of maskedDisplayObject, you should add it to this instead, and check that it's displayed on top of maskedDisplayObject (call addChild(cardLight) after addChild(maskedDisplayObject)).
This all totals to this code:
trace("Stage is null:", (this.stage==null)); // if this outputs true, you're out of display
cardMask = new Image(Root.assets.getTexture("card_mask"));
cardMask.y = Constants.STAGE_HEIGHT*0.40;
cardMask.x = Constants.STAGE_WIDTH *0.48; // mask creation unaltered
trace("it's add mask");
cardLight = new Image(Root.assets.getTexture("card_light_mask"));
cardLight.y = Constants.STAGE_HEIGHT*0.46;
cardLight.x = Constants.STAGE_WIDTH *0.48;
cardLight.mask=cardMask; // this is right
maskedDisplayObject = new PixelMaskDisplayObject(-1,false);
// maskedDisplayObject.addChild(cardLight); this is moved to main part of display list
maskedDisplayObject.x=cardLight.x;
maskedDisplayObject.y=cardLight.y;
// maskedDisplayObject.mask=cardMask; NO masking of this, you're only masking cardLight
cardLight.blendMode = BlendMode.SCREEN; // display mode is also changed
addChild(maskedDisplayObject);
addChild(cardLight);

How to Use .as Exported File from PhysicsEditor

The question was here for a long time with bounty and no satisfying solution for me. I erased the first post and am posting instead a question that can be answered quickly with a yes or no so I can proceed with my doings.
If you could answer it really fast before it's deleted by "not a good question". Is using a custom shape from PhysicsEditor to Nape the same as doing it with Box2D? (ofc changing syntax)
If you could then give a look in that link then say it's the same process in Nape that'll be enought thanks.
I ask this because I found the Box2D tutorial easier to follow so far.
public var floor:Body;
floor = new Body(BodyType.STATIC);
var floorShape:PhysicsData = new PhysicsData();
floor.shapes.add(floorShape); // Error: Implicit coercion of a value of type PhysicsData to an unrelated type nape.shape:Shape.
floor.space = space;
Update:
According to a comment on this blog post, it sounds like recent versions of Nape have broken compatibility with the physics editor. Specifically, the graphic and graphicUpdate properties no longer exist on body objects. The solution suggested is to remove references to those properties.
I'm not in a position to be able to test this, but you could try updating the createBody method of your floor class as follows:
public static function createBody(name:String /*,graphic:DisplayObject=null*/):Body {
var xret:BodyPair = lookup(name);
//if(graphic==null) return xret.body.copy();
var ret:Body = xret.body.copy();
//graphic.x = graphic.y = 0;
//graphic.rotation = 0;
//var bounds:Rectangle = graphic.getBounds(graphic);
//var offset:Vec2 = Vec2.get(bounds.x-xret.anchor.x, bounds.y-xret.anchor.y);
//ret.graphic = graphic;
/*
ret.graphicUpdate = function(b:Body):void {
var gp:Vec2 = b.localToWorld(offset);
graphic.x = gp.x;
graphic.y = gp.y;
graphic.rotation = (b.rotation*180/Math.PI)%360;
}
*/
return ret;
}

Umbraco MediaById not working as expected

Trying to display a set of images from uComponents' MNTP, and can't get a value for the umbracoFile property - in the example below, both umbracoFile and url return empty strings:
foreach (var id in #Model.sliders) {
var media = Model.MediaById(id.InnerText);
if (media != null){
var url = media.umbracoFile;
<p>name = #media.Name</p>
<p>alt = #media.altText</p>
<p>url = #media.umbracoFile</p>
<p>url = #url</p>
}
}
It's getting really really really annoying... I've worked around it in other areas like so, using Model.Media:
<img src="#Model.Media("topRightImage", "umbracoFile")" alt="#Model.Media("topightImage", "altText")" />
But that will only help if with the media picker data type, not mntp. It shouldnt' be that difficult, should it?
I can get the images to load if I rebuild the internal search index, but they're gone again on subsequent refreshes.
I've seen others having similar problems, and would really appreciate a solution...
ta
Nathan
This looks like a bug that was fixed in 4.7.2. See the following codeplex item:
http://umbraco.codeplex.com/workitem/30778