I am trying to use the Flann matcher for matching features between images. Following are few lines of code:
vector<MatchesInfo> matches;
Ptr<FlannBasedMatcher> matcher(new flann::LshIndexParams(20, 10, 2));
matcher.knnMatch(afeatures.descriptors, bfeatures.descriptors, matches, 2);
This generates the following error:
class "cv::Ptr" has no member "knnMatch"
What am I doing wrong?
Try this:
vector<vector< DMatch >> knnMatches;
FlannBasedMatcher matcher;
matcher.knnMatch(desc1, desc2, knnMatches, 50);
If using KNN would also used Lowe's ratios to determine if distance is appropriate between matches. Also make sure that descriptors are of type CV_32F
If you use cv::Ptr, you need to use arrow pointer: ->
But you used dot pointer: .
Change your code as:
matcher->knnMatch(afeatures.descriptors, bfeatures.descriptors, matches, 2);
Related
I'd like to extract the "col" color value from this function to be used to paint plots or candle colors. But everything I try creates one error or another. I checked the Script Reference. Shouldn't there be some way to "return" a value, as is usually the case with most functions?
lset(l,x1,y1,x2,y2,col)=>
line.set_xy1(l,x1,y1)
line.set_xy2(l,x2,y2)
line.set_width(l,5)
line.set_style(l, line.style_solid)
line.set_color(l,y2 > y1 ? #ff1100 : #39ff14) //red : green
temp = line.get_price(l,bar_index) // another value to extract
The documentation is showing it like this:
line.new(x1, y1, x2, y2, xloc, extend, color, style, width) → series line
So in your code it's looking differently and also the "new" is missing.
Scrolling a bit up on the linked page shows that there exist indeed methods to retrieve some properties of the line object:
Lines are managed using built-in functions in the line namespace. They include:
line.new() to create them.
line.set_*() functions to modify the properties of an line.
line.get_*() functions to read the properties of an existing line.
line.copy() to clone them.
line.delete() to delete them.
The line.all array which always contains the IDs of all
the visible lines on the chart. The array’s size will depend on
the maximum line count for your script and how many of those you
have drawn. aray.size(line.all) will return the array’s size.
The most simple usage is to instantiate a line object with the correct values directly, like shown here:
//#version=5
indicator("Price path projection", "PPP", true, max_lines_count = 100)
qtyOfLinesInput = input.int(10, minval = 1)
y2Increment = (close - open) / qtyOfLinesInput
// Starting point of the fan in y.
lineY1 = math.avg(close[1], open[1])
// Loop creating the fan of lines on each bar.
for i = 0 to qtyOfLinesInput
// End point in y if line stopped at current bar.
lineY2 = open + (y2Increment * i)
// Extrapolate necessary y position to the next bar because we extend lines one bar in the future.
lineY2 := lineY2 + (lineY2 - lineY1)
lineColor = lineY2 > lineY1 ? color.lime : color.fuchsia
line.new(bar_index - 1, lineY1, bar_index + 1, lineY2, color = lineColor)
Getting the line color from outside is difficult or impossible though as there never exists a method to retrieve it while for other properties those methods exist.
So the most simple way is to create the same funcionality, to get the color that exists inside the line-object, outside too, or only outside.
currentLineColor = y2 > y1 ? #ff1100 : #39ff14
You could try to extend the line-object somehow like this:
line.prototype.get_color = function() {
return this.color;
};
console.log(line.get_color())
I'm not sure if the approach with the prototype is working but it's worth it to try if you need it.
I am trying a simple function as follows:
function out=Y_T(f,a,b)
Y_T=f(a)-f(b)
end
f is an argument which is a function itself. For example f=x^4+3. The function T_Y should evaluate the values of f in 'a' and 'b' and subtract them. But when i try to use this function for example T_Y(x^4+3,5,2) i face with an error: Index exceeds matrix dimension. How can i fix it? Any tips will be appreciated.
Thanks a lot.
I think you simply have your syntax wrong - as written, you're passing the numeric value x^4 + 3 into Y_T. I think what you need is:
Y_T(#(x) x^4 + 3, 5, 2)
This defines an anonymous function, and passes it in to Y_T.
Your definition of Y_T is slightly wrong too - you need to assign the result to out, like so:
function out=Y_T(f,a,b)
out=f(a)-f(b)
end
I am trying to generate an output as a random number using Postman so that I can PUT it onto a 'thing' in my IoT app
If I give the value in the following format, it works correctly:
{
"WindSpeed" : "88"
}
But now I want to pass on the value of the "WindSpeed" in an automated manner (something like using the random value function) so that I don't have to manually change it every time,
Unfortunately, I am not able to do so as I have trying ways available online including setting global variables etc. etc. but it is always giving an error of 'BAD STRING' or that the JSON content does not have 'ValidProperties' etc. I think that maybe my syntax is wrong. Could someone please guide me as to how I can generate random values in postman(syntax etc.)?
but why not just to use
postman.setEnvironmentVariable("random_list_name", _.random(1,
10000000))
Where "random_list_name" Environment Variable
This is simple and seems does the same
You shall generate your random value in the prescript tab using a function like this one:
// random generator function
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min)) + min;
}
// generate the random value
const myval = getRandomInt(0,100);
// set the value into the global variable
pm.globals.set('value', myval);
// to see it in console
console.log(myval);
Then, in your JSON body, you shall use it:
{
"Windspeed":{{value}}
}
This should work.
Angualr JS code:
$scope.rupee = $filter('currency')($scope.dols * 67.33, 'INR', 3);
I am trying to insert html code inside this filter. That is instead of 'INR', I wish to get ₹ symbol. Please help me to solve this. And the problem is not getting the ₹ through filter. Instead of 'INR', I want to use ₹ but it's not rendering as I expected.
html code:
<div>{{rupee}}</div>
Modify your statement to
$scope.rupee = $filter('currency')($scope.dols * 67.33, '\u20B9', 3);
As you asked, "Can we write HTML code inside symbolFormat parameter?"
Answer will be below:
It takes a string parameter, so whatever string you are providing, it will be used to apply as currency symbol
For reference you can check Here
You can try like this:
{{ currency_expression | currency : symbol : fractionSize}}
$scope.rupee = $filter('currency')($scope.dols * 67.33, '₹', 3);
See all use cases (currency symbol & sign - in controller & directly on view):
<div ng-app ng-controller="RupeeCtrl">
<b>From controller with sign</b><br/>
{{rupeeSign}}
<br/><br/>
<b>From controller with code</b><br/>
{{rupeeCode}}
<br/><br/>
<b>From view</b><br/>
{{ price | currency:'₹'}}
</div>
function RupeeCtrl($scope, $filter) {
$scope.price = 75.255;
$scope.rupeeSign = $filter('currency')($scope.price, '₹', 3);
$scope.rupeeCode = $filter('currency')($scope.price, '\u20B9', 3);
}
JSFiddle
Mixed with answer from #Romesh Jain
This looks like a duplicate question to this: How to get specific currency symbol(rupee symbol in my case) in angular js instead of the default one (dollar $ symbol)
Just use this ASCII code for the Rupee symbol: ₹
See the ASCII code here: http://www.fileformat.info/info/unicode/char/20b9/index.htm
I'm trying to do some re-factoring on my charts to make them re-usable using this as a guide: http://bost.ocks.org/mike/chart/
I'm having problems drawing the lines in my multi-line graph though - specifically passing the data to the x and y values. If I hard code the element names it works, but if I try to use the xValue and yValue objects this does not work. I'm assuming that this is because I'm trying to call a function within the parameter of an other object, but I'm not sure how to get around this. In the exmaple Mike uses d[0] and d[1], but this won't work with JSON data (or I'm not sure how to make it work).
I've posted this JSFiddle so you can see the code. The problem lines are 125 to 131 which in turn is being called from line 165.
var main_line = d3.svg.line()
.interpolate("cardinal")
// Hard coding the elements works
//.x(function(d) { return main_x(d.date); })
//.y(function(d) { return main_y(d.buildFixTime); });
// Passing xValue and yValue does not work
.x(function(d) { return main_x(xValue); })
.y(function(d) { return main_y(yValue); });
http://jsfiddle.net/goodspeedj/fDyLY/
Thank you in advance.
You need to redefine your accessor method within .x() and .y(). The accessor method defines the way that a datum is pulled out of the data that is bound to the selection that you call the line generator on.
Suppose you have a relatively flat data structure such as the following.
data = [{x : 1, y : 2}, {x:1, y:3}, {x:4, y:5}];
You then bind the data to a selection with the following statement
d3.select("body").datum(data).append("path").attr("d",lineGenerator);
Quite a bit is going on underneath this statement. I'll give you a bit more of a walkthrough after showing you a commonly used example.
The important aspect to understand is that similarly to other calls in d3 such as
var exampleRectangles = d3.select("body")
.data(data).enter()
.append("rect")
.attr("width",2)
.attr("height", 3)
.attr("x",function(datum){return datum.x}) // pay attention to this line
.attr("y",0);
d3 is implicitly iterating over each element in your data. For each datum in your data array, in this case there is a total of three datum, you are going to add a rectangle to the dom.
In the line that I tell you to pay attention to you notice that you're defining an anonymous (unnamed) function. What is that datum parameter coming from? It's implicitly being passed to your anonymous function.
So each rectangle has it's own corresponding datum {x : 1, y : 2}, {x:1, y:3}, {x:4, y:5} respectively. Each rectangle's x coordinate is defined by the respective datum.x attribute. Under the sheets, d3 is implicitly looping over the data array that you've defined. A similar approach to the example d3 code could be written as above.
for (var i = 0; i < data.length; i++)
{
d3.select("body").append("rect")
.attr("width",2)
.attr("height", 3)
.attr("x",data[i].x)
.attr("y",0);
}
This follows from the notion of data driven documents (d3). For each item added (a rectangle in the above example a piece of data is tied to it. In the above example you see that there is something kind of similar to your .x() and .y() accessor functions :
.attr("x",function(datum){return datum.x})
This function is telling d3 how to filter over the total datum that's being passed to the .attr() accessor method.
So, you need to determine which data you need to get a hold of to make your .attr("d", lineGenerator)call make sense. The difference between your.datum(data)call and the typical.data(data)call is that instead of parceling the data that's being passed to.data(data)`, the whole array is given as a single piece of data to the line generator function (similar to main_line(data), wherein it will again implicitly loop over the points to construct your path.
So, what you need to do is determine what a single datum will be defined as for your function to operate on.
I'm not going to define that as I don't seem to know quite which information you are operating on, but I would hazard a guess at something like.
.x(xAccessor)
.y(yAccessor)
function xAccessor(datum)
{
return xScale(datum._id.month);
}
function yAccessor(datum)
{
return yScale(datum.buildFixTime);
}
The way you have it set up, xValue and yValue are functions; you have to actually execute them on something to get a value back.
.x(function(d) { return main_x( xValue(d) ); })
.y(function(d) { return main_y( yValue(d) ); });
If you weren't using a scale, you could use
.x(xValue)
.y(yValue);
but only because if you pass in a function d3 executes it for you with the data as a parameter. And that only works for d3 methods that expect functions as possible input -- the scale functions expect data values as input.
I wrote a long piece work for another user last week that you may find useful, explaining methods that accept functions as parameters.