dlib.rectangle Failing expression was p.is_empty() == false - dlib

I am using Dlib by Davis King in Python, I'm using its Correlation tracker feature where I have to specify the rectangle on a frame which is read from my webcam
I am using Yolo v3 to get the coordinates of the detected object like Car or Person then pass them to start_track like this
tracker = dlib.correlation_tracker()
dlib_rect = dlib.rectangle(left, top, bottom, right)
tracker.start_track(frame, dlib_rect)
I know my coordinates are right and if I just draw them without tracking, they are showing bounding boxes on the correct objects detected by Yolo v3 but when I am using them in the start_track method I get the following error
tracker.start_track(frame, dlib_rect)
RuntimeError:
Error detected at line 61.
Error detected in file e:\documents\projects\dlib\dlib\image_processing\correlation_tracker.h.
Error detected in function void __cdecl dlib::correlation_tracker::start_track<class dlib::numpy_image<struct dlib::rgb_pixel>>(const class dlib::numpy_image<struct dlib::rgb_pixel> &,const class dlib::drectangle &).
Failing expression was p.is_empty() == false.
void correlation_tracker::start_track()
You can't give an empty rectangle.

Thanks to Davis King himself for pointing out I had the wrong parameter ordering
Rectangle should have been defined as
dlib_rect = dlib.rectangle(left, top, right, bottom)

Related

Building umlet custom elements

I am trying to do a collaboration diagram in umlet, but there isn't a palette element to do so. So I thought I'd create one. Easier said than done! I am able to define the class element of the diagram, but am unable to define the arrows that define the flow of the collaboration.
I've tried adding a drawline statement to the code window, but it is undefined in umlet custom element implementation.
//Modify the code below to define the element's behavior.
//
//Example: Change the line
// y += printCenter(textline,y);
//to
// y += 2*printCenter(textline,y);
//and observe the element preview.
int y=textHeight();
drawRectangle(0,0,100,35);
drawRectangle(0,150,100,35);
//drawline(10,35,10,115);
for(String textline : textlines) {
y += printCenter(textline,y);
}
The expected result should be two class elements and two arrows denoting the flow of the collaboration.
I've gotten this far, but I am unable to save it to the custom elements palette.
Welllll, my bad! It turns out that you can use the regular palette elements to construct the diagram and then save it to umlet's palettes directory.

Three.js simple custom animation does not continue changing with DAT.GUI .onChange function

Apologies if my mistake is obvious. Started learning code a few weeks ago. Have searched copiously for an answer.
Attempting to control a variable of a graphical equation animated in three.js using Dat.Gui. By assigning the variable to nothing, I was able to see that the gui is linked because clinking anywhere on the slider immediately calls the intended graphed equation (for simplicity's sake I have replaced my more complicated equation with a simple parabola). The graphed equation also disappears when the gui slider is clicked again, as hoped, to clear the way for the 'redrawn' equation (wider or skinnier parabola as determined by gui slider), however it throws this error:
"[.CommandBufferContext]RENDER WARNING: Render count or primcount is 0."
I've been able to rearrange the code so it doesn't throw this error, but it still does not call the next visible iteration of the equation.... Below is the code that succeeds in drawing the parabola, removes it upon the next .onChange, but then throws the above error...
init function + scene, camera setup, etc....
gui = new DAT.GUI();
gui_a = gui.add(this, 'a').min(0.01).max(5).step(0.01).name('Width');
gui_a.onChange(function(value){createGraph();});
}
function createGraph(){
if(graphLine) scene.remove(graphLine);
var graphGeometry = new THREE.Geometry();
while (x<20){
var y = a*(Math.pow(x,2));
next_x = x+0.05;
next_y = a*(Math.pow(next_x,2));
x=x+0.05;
graphGeometry.vertices.push(
new THREE.Vector3(x, next_y),
new THREE.Vector3(next_x, next_y)
);};
graphLine = new THREE.Line(graphGeometry, material);
scene.add(graphLine);
};
Help would be hugely appreciated.
Figured out my own problem... quite simple as I thought: the value of 'x' is not getting reset in creategraph();. It is defined with variables at the top of the code as "var x = -20" (which is not visible in my post..). Therefore the 'second' rendering of the graph is starting at x = 20, instead of reverting back to the original x=-20.

Unable to get the location bound of Sketchup model using Sketchup Ruby API

I have a Sketchup 3d model that is geo-located. I can get the geo-location of the model as follows :-
latitude = Sketchup.active_model.attribute_dictionaries["GeoReference"]["Latitude"]
longitude = Sketchup.active_model.attribute_dictionaries["GeoReference"]["Longitude"]
Now i want to render this model on a 3D globe. So i need the location bounds of the 3d model.
Basically i need bounding box of the model on 2d map.
Right now i am extracting the same from the corners of a model(8 corner).
// This will return left-front-bottom corner.
lowerCorner = Sketchup.active_model.bounds.corner(0)
// This will return right-back-top corner.
upperCorner = Skectup.active_model.bounds.corner(6)
But it returns simple geometrical points in meters, inches depending upon the model.
For example i uploaded this model in sketchup. Following are the values of geo-location, lowerCorner and upperCorner respectively that i'm getting by using the above code for the above model.
geoLocation : 25.141407985864, 55.18563969191 //lat,long
lowerCorner : (-9483.01089", -6412.376053", -162.609524") // In inches
upperCorner : (-9483.01089", 6479.387909", 12882.651999") // In inches
So my first question is what i'm doing is correct or not ?
Second question is If yes for the first how can i get the values of lowerCorner and upperCorner in lat long format.
But it returns simple geometrical points in meters, inches depending upon the model.
Geom::BoundingBox.corner returns a Geom::Point3d. The x, y and z members of that is a Length. That is always returning the internal value of SketchUp which is inches.
However, when you use Length.to_s it will use the current model's unit settings and format the values into that. When you call Geom::Point3d.to_s it will use Length.to_s. On the other hand, if you call Geom::Point3d.inspect it will print the internal units (inches) without formatting.
Instead of tapping into the attributes of the model directly like that I recommend you use the API methods of geo-location: Sketchup::Model.georeferenced?
By the sound of it you might find Sketchup::Model.point_to_latlong useful.
Example - I geolocated a SketchUp model to the town square of Trondheim, Norway (Geolocation: 63°25′47″N 10°23′36″E):
model = Sketchup.active_model
bounds = model.bounds
# Get the base of the boundingbox. No need to get the top - as the
# result doesn't contain altiture information.
(0..3).each { |i|
pt = bounds.corner(i)
latlong = model.point_to_latlong(pt)
latitude = latlong.x.to_f
longitude = latlong.y.to_f
puts "#{pt.inspect} => #{longitude}, #{latitude}"
}

Transforming an image using a known displacement field with imwarp in matlab

I wish to transform an image using a known displacement field but am having issues using the imwarp function for this. Any help would be very very appreciated
I use a grid in order to project an image onto a known plane. By detecting the location of the grid points in the image and comparing them to the location in "real" space I am able to come up with a matrix, D_OH, of size [m, n, 2] which represents the x and y displacements required.
I use the line:
OH_grid_avg_mapped = imwarp(OH_grid_avg_post, D_OH)
but get the following errors:
Error using imwarp
Expected tform to be one of these types:
images.geotrans.internal.GeometricTransformation
Instead its type was double.
Error in imwarp>validateTform (line 367)
validateattributes(t,{'images.geotrans.internal.GeometricTransformation'},{'scalar','nonempty'},'imwarp','tform');
Error in imwarp>preparseSpatialReferencingObjects (line 384)
validateTform(tform);
Error in imwarp (line 136)
[R_A, varargin] = preparseSpatialReferencingObjects(varargin{:});
Error in VizExpt_SchlierenOHAlign_v7 (line 261)
OH_grid_avg_mapped = imwarp(OH_grid_avg_post, D_OH);"

dc.js line chart with range of colors

I have a composite graph of two line charts. For one of them i'm attempting to apply a custom color range based on the value of each point on the line:
.colors(['rgb(215,48,39)','rgb(244,109,67)','rgb(253,174,97)','rgb(254,224,144)'])
.colorDomain ([0,3])
.colorAccessor (d,i) ->
if d.points[i].data.value.avg > 50
return 0
else
return 3
The problem is I keep getting only one color for the entire graph... Not to mention d returns as an object of all the points instead of a single point... (maybe a hint of the problem?)
Am i doing something wrong here and/or is there an easier way to do this?
You didn't get an answer so I'll try to look into it with you.
First, I created a fiddle at http://jsfiddle.net/djmartin_umich/4ZwaG/.
.colors( ['rgb(215,48,39)', 'rgb(244,109,67)', 'rgb(253,174,97)', 'rgb(254,224,144)' ] )
.colorDomain ([0,3])
.colorAccessor(function(d, i){
if(d[i] && d[i].data.value > 150)
return 3;
else if(d.data.value > 150)
return 2;
else return 1;
});
I had to play around with the color accessor to get it to stop throwing errors. The method was called twice with an array of elements and twice for each element in the array (24 times total).
Once I got it compiling I inspected the chart and saw this:
The chart has a path element that defines the line and a bunch of circles that define the points on the line. The points are part of the tool-tip that display when you hover over the different points on the line.
The path seems to be colored by the value returned when the array of values was passed in and the hover-points on the line are each colored by the value returned for that element.
So the path of the line is given a single color. It sounds like your expectation is for different portions of the line to be colored differently based on their y-value, but this is not how the line is rendered.
The article at http://www.d3noob.org/2013/01/applying-colour-gradient-to-graph-line.html describes how you can use gradients to achieve the effect you desire. I believe the author is "hard-coding" the start and stop points for each gradient, so it won't get you all the way to your answer but it should help you get started.
I hope this helps!
-DJ

Resources