rotate() in Eigen::Transform is not transforming my rotation matrix - matrix

I have defined a rotation matrix and wanted the Eigen::Transform to perform rotation. For some reason, it is still set at identity although I am rotating it.
//Definig my rotation matrix
Eigen::Matrix3f roll_rotation_matrix( 3, 3 );
roll_rotation_matrix << 1, 0, 0, 0, 0, 1, 0, -1, 0;
//Print
display("PRINT ROLL ROTATION: ")
display(roll_rotation_matrix)
// Perform rotation along X
display("BEFORE: ")
display(roll_input_stamped_transform.transform.rotation())
//Rotate the rotation matrix
roll_input_stamped_transform.transform.rotate( roll_rotation_matrix );
roll_input_stamped_transform.transform.rotation = roll_rotation_matrix;
//Print
display(" AFTER: ")
display(roll_input_stamped_transform.transform.rotation());
And my output here is as below:
PRINT ROLL ROTATION:
1 0 0
0 0 1
0 -1 0
BEFORE:
1 0 0
0 1 0
0 0 1
AFTER:
1 0 0
0 1 0
0 0 1
As I am printing my roll_rotation_matrix, I can see that my matrix is not identity. But, even after applying rotate(), the rotation matrix still seems to be at identity.
Do you guys have any clue as to what might me going on here?

Figured out the issue.
I had to set the roll_input_stamped_transform.transform.setIdentity() in order for it to apply my rotation matrix.

Related

How to segment image with a set of points, assign each pixel to the nearest point?

I try to implement a method to segment image with seed points, and assign each pixel to nearest point.
for example, if the pixel close to 1, then set to 1.
input:
0 0 0 0 0 3 0
0 1 0 0 0 0 0
0 0 0 0 2 0 0
0 0 0 0 0 0 0
output:
1 1 1 3 3 3 3
1 1 1 2 2 3 3
1 1 1 2 2 2 2
1 1 1 2 2 2 2
current the method take too long time and calculate (width * height * numPoints) times, is there any algorithm can be faster?
7 seconds to process 5 9478 * 1868 images, numPoints = 8
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
byte index = 0;
double distance = double.MaxValue;
for (int m = 0; m < elements.Count; m++)
{
CircleROI circle = roiResized[m];
double currentDistance = Math.Abs(i - circle.Center.Y) +
Math.Abs(j - circle.Center.X);
if (currentDistance < distance)
{
distance = currentDistance;
index = (byte)m;
}
}
*data++ = index;
}
}
You can make your program work in time proportional to the number of pixels.
Maintain a queue of the pixels you're currently "working on".
Initialise this queue so that it contains all the pixels that are initially non-zero.
Then loop while the queue is not empty:
Pop a pixel (x, y) from the queue;
Colour every zero neighbour of (x, y) in the same colour as (x, y);
Add every pixel that you have coloured to the queue.
That's actually a "Voronoi tessellation", so you can use that term to research optimal methods.
You can demonstrate it by taking:
red for your colour 1 at coordinates (1,1)
lime green for your colour 2 at coordinates (4,2)
blue for your colour 3 at coordinates (5,0)
and scaling your input diagram by a factor of 10 to make the result large enough to see. Then draw it with ImageMagick in the Terminal:
magick -size 60x30 xc: \
-sparse-color Voronoi '10,10 red 40,20 lime 50,0 blue' \
result.png
If you just want to stick to single-channel greyscale, rather than colour, you can use:
magick -size 60x30- xc: \
-sparse-color Voronoi '10,10 black 40,20 gray 50,0 white' result.png
There is an excellent discussion and tutorial on this and similar techniques by Anthony Thyssen here.
It is related to the "Delaunay Triangulation" and, though I have not tested it, I expect the OpenCV implementation will be extremely fast.

3d collision formula based on xyz

Here is the problem. We have two points (spheres) in xyz, with this info:
1- x,y,z => The center of the object is currently located at
2- r => The collision radius of the object
3- Vx, Vy, Vz => object is traveling along the vector. If that vector is (0,0,0), the object is stationary.
Note: The radii and positions are in meters and velocities are measured in meters per second.
Question: For each test, output a single line containing the time (in seconds) since the start of the test at which the two objects will first collide. If they never collide, print No collision instead.
I want to know about the formula of calculation this time. Any idea would be appreciated.
Examples:
1-
xyz(1): -7 5 0
v(1): -1 0 3
r(1): 3
xyz(2): 10 7 -6
v(2): -2 0 4
r(2): 6
t: 8.628 // this is the answer
2-
xyz(1): 10 3 -10
v(1): -9 3 -8
r(1): 5
xyz(2): 2 0 0
v(2): 6
r(2): -4 3 -10
t: 0.492 // this is the answer
To simplify problem, let us use Halileo's principle. Consider the first object as base point, so the second objects moves relative to it.
Put the first object position in coordinate origin.
Subtract the first object initial coordinates from the second one coordinates, do the same for velocity components
x2_0 = x2_0 - x1_0 (same for y,z)
Vx2 = Vx2 - Vx1 (same for y,z)
Now we have second center coordinates against time
x = x2_0 + Vx2 * t
y = y2_0 + Vy2 * t
z = z2_0 + Vz2 * t
and squared distance to origin:
dd = x*x + y*y + z*z =
(x2_0 + Vx2 * t)^2 + ... =
x2_0^2 + 2*x2_0*Vx2*t + Vx2^2*t^2 + ...
and we need to calculate when dd becomes equal to squared radius sum (r1+r2)^2
t^2 * (Vx2^2+Vy2^2+Vz2^2) + t*(2*x2_0*Vx2+2*y2_0*Vy2+2*z2_0*Vz2) +
x2_0^2 + y2_0^2 + y2_0^2 - (r1+r2)^2 = 0
Solve this quadratic equation for t, get 0,1 or 2 solutions.
Case of 0 solutions - no collision
Case of 1 solution with positive t - moment of touching
Case of two solutions - get smaller positive t for the moment of collision.
Negative values of t mean collision "in the past", before the start of the test
Quick test in Python (ideone)
from math import sqrt, isclose
def collisiontime(x1,y1,z1,vx1,vy1,vz1,r1, x2,y2,z2,vx2,vy2,vz2,r2):
x2 -= x1
y2 -= y1
z2 -= z1
vx2 -= vx1
vy2 -= vy1
vz2 -= vz1
a = vx2**2 + vy2**2 + vz2**2
b = 2*x2*vx2 + 2*y2*vy2 + 2*z2*vz2
c = x2**2 + y2**2 + z2**2 - (r1+r2)**2
D = b**2-4*a*c
if D < 0:
return None
if isclose(D, 0):
return -b/2/a
return (-b - sqrt(D)) / 2 /a, (-b + sqrt(D)) / 2 /a
print(collisiontime(0, 0, 0, 2, 0, 0, 2, 25, 0, 0, -3, 0, 0, 3)) # 1=> <=2
print(collisiontime(0, 0, 0, 2, 0, 0, 2, 25, 5, 0, 1, 0, 0, 3)) # 1==> 2=> chase with touching
print(collisiontime(-7, 5, 0,-1, 0, 3, 3, 10, 7, -6, -2, 0, 4, 6))
print(collisiontime(10, 3, -10,-9, 3, -8,5, 2, 0, 0, -4, 3, -10, 6))
(4.0, 6.0)
25.0
(8.627718676730986, 14.372281323269014)
(0.4917797757201004, 3.646151258762658)

Display label on gnuplot value in heatmap

Base on gnuplot example about "Heat map with non-zero pixel values written as labels" in here:
http://gnuplot.sourceforge.net/demo_cvs/heatmaps.html
I have data:
6 5 4 3 1 0
3 2 2 0 0 1
0 0 0 0 1 0
0 0 0 0 2 3
0 0 1 2 4 4
0 1 2 3 4 6
and my gnuplot:
set terminal pngcairo enhanced font "arial,10" fontscale 1.0 size 500, 350
set output 'heatmaps.png'
unset key
set view map
set xtics border in scale 0,0 mirror norotate offset character 0, 0, 0 autojustify
set ytics border in scale 0,0 mirror norotate offset character 0, 0, 0 autojustify
set ztics border in scale 0,0 nomirror norotate offset character 0, 0, 0 autojustify
set nocbtics
set rtics axis in scale 0,0 nomirror norotate offset character 0, 0, 0 autojustify
set xrange [ -0.500000 : 4.50000 ] noreverse nowriteback
set yrange [ -0.500000 : 4.50000 ] noreverse nowriteback
set cbrange [ 0.00000 : 5.00000 ] noreverse nowriteback
set palette rgbformulae -7, 2, -7
splot 'heatmap.txt' matrix using 1:2:3 with image, \
'heatmap.txt' matrix using 1:2:($3 == 0 ? " " : sprintf("$3") ) with labels
this script just printout "3" in every labels. Could you help me? thanks
and also label for Xtics and Ytics
Tipe1 Tipe2 Tipe3 Tipe4 Tipe5
Failure1 6 2 0 0 1
Failure2 0 0 0 1 0
Failure3 0 0 0 2 3
Failure4 0 1 2 4 4
Failure5 1 2 3 4 6
Thanks again
I think the problem is the wrong call to the sprintf function.
sprintf(format,values)
You should call sprintf with a decimal number in format (%d) and the label value you want to display (third column $3) :
sprintf("%d",$3)
I copied your data into a file (named data) and this example works well :
plot 'data' matrix using 1:2:3 with image, '' matrix using 1:2:($3==0 ? " " : sprintf("%d",$3)) with labels
Hope it helps!

How to control size of validity icon in a pdf

I've been trying for at least 2 days now to control the size of the validity icon of a pdf file, when signed.
The icon is set by the pdf reader usually.
I've tried different approaches to the problem :
Redimensioned the Signature Annotation Rectangle - which reshaped
all the contents within
Redimensioned the Signature Annotation Appearance BBox - which also
reshaped the text and icon contents.
I've also tried to reshape n2 and n0 layers, and created a new one
n5, expecting to be able to control it's size without success
In the end, I would just want to individually resize the validity icon.
Any suggestions shall be deeply appreciated.
dsblank = Annotation::AppearanceStream.new.setFilter(:FlateDecode)
dsblank.Type=Name.new("XObject")
dsblank.Resources = Resources.new
dsblank.BBox = [ 0, 0, width, height ]
dsblank.draw_stream('% DSBlank')
n2 = Annotation::AppearanceStream.new.setFilter(:FlateDecode)
n2.Resources = Resources.new
n2.BBox = [ 0, 0, width, height ]
n2.draw_stream('% DSBlank')
n5 = Annotation::AppearanceStream.new.setFilter(:FlateDecode)
n5.Resources = Resources.new
n5.BBox = [ 0, 0, width, height ]
n5.write(caption,x: padding_x, y: padding_y, size: text_size, leading: text_size )
sigannot = Annotation::Widget::Signature.new
sigannot.Rect = Rectangle[ llx: x, lly: y, urx: x+width, ury: y+height ]
sigannot.F = Annotation::Flags::PRINT #sets the print mode on
#
# Creates the stream for the signature appearance
#
streamN = Annotation::AppearanceStream.new.setFilter(:FlateDecode)
streamN.BBox = [ 0, 0,width, height]
streamN.Resources = Resources.new
streamN.Resources.add_xobject(Name.new("n0"), dsblank)
streamN.Resources.add_xobject(Name.new("n1"), dsblank)
streamN.Resources.add_xobject(Name.new("n2"), n2)
streamN.Resources.add_xobject(Name.new("n3"), dsblank)
streamN.Resources.add_xobject(Name.new("n5"), n5)
streamN.draw_stream('q 1 0 0 1 0 0 cm /n0 Do Q')
streamN.draw_stream('q 1 0 0 1 0 0 cm /n1 Do Q')
streamN.draw_stream('q 1 0 0 1 0 0 cm /n2 Do Q')
streamN.draw_stream('q 1 0 0 1 0 0 cm /n3 Do Q')
streamN.draw_stream('q 1 0 0 1 0 0 cm /n5 Do Q')
sigannot.set_normal_appearance(streamN)
page.add_annot(sigannot)
This is not an answer showing how to fix it but more a comment arguing that it is a bad idea to try it at all. It is too big for a comment field, though.
You are trying to manufacture PDFs to support an Adobe Reader feature which Adobe has started phasing out a long time ago, with Adobe Reader 9!
(page 10 of Adobe Acrobat 9 Digital Signatures, Changes and Improvements)
Thus, even if you achieve your goal for now with the current Adobe Reader, it may very easily happen that in upcoming new Adobe Reader version support for this feature will completely be stopped.
Furthermore you wont find any mentioning of this feature (changing signature appearances) in the current PDF specification ISO 32000-1, let alone the upcoming ISO 32000-2.
Also maintenance of support for layers except n0 and n2 had already been stopped in Acrobat 6.0:
(page 8 of Adobe® Acrobat® SDK Digital Signature Appearances, Edition 1.0, October 2006)
After some iterations I managed to get a scale factor of 3 for streamN and n2, as well as padding_y. I also add to increase the text_size.
With that I managed to reduce the size of the icon, and still have legible text.
n2 = Annotation::AppearanceStream.new
n2.Resources = Resources.new
n2.BBox = [ 0, 0, width*3, height*3 ]
n2.write(caption,x: padding_x, y: padding_y*3, size: text_size, leading: text_size )
sigannot = Annotation::Widget::Signature.new
sigannot.Rect = Rectangle[ llx: x, lly: y, urx: x+width, ury: y+height ]
sigannot.F = Annotation::Flags::PRINT #sets the print mode on
#
# Creates the stream for the signature appearance
#
streamN = Annotation::AppearanceStream.new.setFilter(:FlateDecode)
streamN.BBox = [ 0, 0, width*3, height*3 ]

Why I cannot control intensity of color's components in imshow?

I have the following code:
red = [1 255 0; 0 0 0; 0 0 0];
green = [0 0 0; 0 0 0; 0 0 0];
blue = [0 0 0; 0 0 0; 0 0 0];
figure,imshow(cat(3,red,green,blue))
According to my "intuitive" understanding the color of the first pixel of the image should have the following rgb components: (1,0,0), while the second pixel should have the following components: (255,0,0) (when I say the "first" and "second" I mean the text order: from left to right, from top to bottom).
In other words the first pixel should be almost absolutely black while the second one should be red. However, the both pixels look perfectly red. What am I missing here?
I'm no expert, but I think it's because you're passing doubles to imshow. You could try
imshow(uint8(cat(3, red, green, blue)))

Resources