Wednesday, April 8, 2020

Save camera settings to the camera via Basler Pylon


If a Basler Ace loses power it will lose any changed settings.  Saving the settings in the camera is not easy to figure out.  The video describes the problem, and shows how to use Basler Pylon software to save the settings in the camera.

Save Camera Settings via Basler Pylon

The camera can store all of it's settings for up to three users.  The default user settings, called "User Set 1", are loaded when the camera powers up.  Saving the settings to "User Set 1" is not available unless the software is in "Guru" mode.

Here are the steps you need to follow to save the settings in the camera.
1) Connect to the camera
2) If the feature window is not open, click the "View|Features [cameraname]" menu
3) At the bottom of the feature window, select "User Level : Guru"
4) Access the camera's features by expanding the list.  Click on the "> cameraname" to expand the features.
5) Change the features as needed.  Exposure is in Acquisition control, gain is in Analog control.
6)  Save the to the camera, scroll down and expand "> Configuration Sets".
7) Change "Configuration Set Selector" to "User Set 1"
8) Click the "User Set Save" "Execute" button
9) Change "Default Startup Set" to "User Set 1"
illustration for step 2) open the feature window


illustration step 3) change to Guru

illustration step 4) expand list for the camera


illustration step 5) edit features

illustration steps 6 - 9)

Basler Pylon software download link: https://www.baslerweb.com/en/products/software/

Sunday, February 2, 2020

Intel Realsense T265 Quaternion considerations

It has taken me a while to figure out how to use the camera pose data sent from the T265.
The Intel Realsense T265 pose a combination of a quaternion and translation vector.

Lets define some things:
  Camera Pose: the location and orientation of the camera in space.  Relative to the world coordinates.
https://docs.opencv.org/master/dc/d2c/tutorial_real_time_pose.html

  Quaternion: A 4D representation of 3D rotation and/or orientation.  Useful because quaternion math is faster than matrix algebra and does not have gimbal lock error.  There are multiple ways of representing a quaternion.
different ways of writing a quaternion.  Image credit Wikepedia.
All of them are derived from rotating around a vector.  (i.e. rotating theta radians around vector v)
All quaternion represntations have a real number and 3 complex number.  The real number is the cosine (rotation angle/2).  The complex values are the sine (rotation angle /2) multiplied by the vector defining the axis of rotation in x,y, and z.  The three values scale complex values i, j, and k respectively.  - Look, it's a complicated thing to get you mind around, that's why it took me about a year to understand (well.. and I ain't that smart anyhow).  It's funny, I kind of sense (or even feel) an interpretation of a matrix, but not a quaternion. I think it's the 1/2 angle that gets me.  And double coverage is weird. You can get the same rotation by going in different directions ( think -180 and 180 degrees).  Make sure you check out item #6 below for help visualizing quaternions.

  Translation vector: a 3D value representing the direction and magnitude in X, Y, Z coordinates that an object (camera) has moved.

  Rotation matrix: A 3x3 set of numbers that represents where the unit vectors for +x, +y, and +z axes will be located in world coordinates, as long as they start at the origin 0,0,0 (and have length equal to 1).

  R|t matrix: A 4 x 3 matrix made up of the Rotation matrix and the translation vector.  The camera pose can be represented as an R|t matrix.  The quaternion must be converted to the R matrix.
R|t matrix (used as camera pose matrix)
In practice,you want to turn this into a 4x4 homogeneous matrix where the
bottom row = 0 0 0 1
That allows square matrices to be multiplied together.  
Some of the types of 4x4 homogeneous matrices that can be combined by matrix multiplication.
https://sinestesia.co/blog/tutorials/python-cube-matrices/

  Essential Matrix: Not to confuse things too much, but the R|t matrix can be defined as a 3 x 3 matrix called the essential matrix. It is not used in this blog post.  I just wanted to drop a note about it.  It is typically used to find the 3D point correspondence from two camera poses.  The essential matrix associates a 2D point in an image with a line that exists in both camera images.  However, to create the essential matrix the 3 x 3 Rotation matrix is multiplied by the Skew Symmetric form of the translation vector t.  You can retrieve R and t from the essential matrix.  Check the Wikipedia page for Essential matrix.  Look at the section "Determining R and t from E".

--

I started to use the Intel Realsense cameras while at the same time learning linear algebra.  Because I didn't know about the advantages that quaternions have when interpolating movement, I continued down the matrix path.   That meant the quaternion pose data needed to be converted to a rotation matrix.  Wikipedia has an article, but I found some code examples that allowed me to convert a quaternion to a rotation matrix, and a rotation matrix to a quaternion.  There were, of course, errros.  some were mine, and some were documentation.



The key shortcuts I needed are outlined here:

1) The T265 Pose axes are not in the same orientation as the D435.
D435 Pose axes

T265 pose axes


T265 Z and Y axis are rotated around x axis (in relation to the D435)
D435 above a T265.  Y axis revered, Z axis revered. X axis aligned.
You need an R|t matrix to get from T265 pose data to D435 pose.


2) The Quaternion value displayed is not in the order that most quaternion explanations use.  Most use the format where the real value is on the left, followed by the i, j, k complex valued to the right of the real.  The Realsense viewer places the real value on the right.
Realsense quaternions are displayed [x,y,z,w].  The display does not label the elements.
Most formulas would be formatted as [w,x,y,z], or  a+bi+cj+dk or qr, qx,qy,qz.  In all those cases the real is on the left, complex on right. 

3)  The T265 camera orients itself to gravity.  It decides where up is, then once it has a valid pose, it projects that x and z axes on the ground plane.  That's how it defines its world coordinates.


4) If you want to convert the quaternion to a Rotation matrix take a look at this site
https://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToMatrix/index.htm  - But caution... There are errors in thier code.

or try Quaternion Derived rotation matrix on wikipedia, its just, um, Wikipedia, so you might need a masters degree to understand it.

Here is a link to my LabView code that will convert the quaternion to a rotation matrix
https://drive.google.com/drive/folders/1rJ3j662i-Naq2tXvlYXebeRyU57GD1RZ?usp=sharing
If you use it, you to take all the blame and give me all the credit.  And if you make something that is a financial success cut me in on the money.
oh boy, math.  that's fun.


5)  It is not easy to "see" how the quaternion converts to a rotation matrix.
  Here are some quaternion to rotation matrix examples






6) Have a look at the 3 blue one brown collaboration with eater.net to Visualize Quaternions
It is the most helpful thing on the internet regarding quaternions.

Monday, January 13, 2020

The striking similarity between Laser Transverse Electromagnetic modes and Hydrogen atomic orbital probability

These charts are remarkably similar, but represent different types of particles.

Laser Transverse Modes
Laser Transverse Electromagnetic (TEM) modes
Atomic orbitals of the electron in an atom of hydrogen
Atomic orbitals of the electron in an atom of hydrogen

The orbital graph is based on the probability that an electron exists in the space around the hydrogen nucleus.  The laser transverse electromagnetic modes are formed in a waveguide.  Both graphics are 2D representations / cross sections of a 3D shape.

  The similarity makes me think that the electrons are waves in a waveguide.  Something that makes the atom the waveguide. 

  Note that TEM00, and TEM34 don't have a corresponding shape in the hydrogen probability graph.


- As we build quantum computers, are we just building complex Bose Einstein condensate interferometers?
? Is shore's algorithm computational Fourier transform interferometery in band limited waveguided 3D?


-- Edit 20200129 - acoustic standing waves where the cymbal is the waveguide:
https://ars.els-cdn.com/content/image/1-s2.0-S0888327016304770-fx1_lrg.jpg
The subpixel resolution of optical-flow-based modal analysis:
https://www.sciencedirect.com/science/article/abs/pii/S0888327016304770

The wave modes are similar to TEM and electron probability above images.

-- Edit 20200718 - Quantum theory goes on and on about electrons acting like standing waves around a nucleus.  https://www.grandinetti.org/quantum-theory-matter


-- edit 20200919 - 3d modeling software - used for modeling nebulae 
see figure 12 in this pdf: https://arxiv.org/pdf/2009.08272.pdf





Tuesday, January 7, 2020

Thumper, my pet rabbit.


I wrote this story back in 2011.  It's about the pet rabbit I had in the 1980's


Thumper, My Pet Rabbit.

  Thumper, a gray fluffy sausage of a rabbit, liked to sit on my head when we were both younger. Thumper, a mixed checker and Californian, got too fat to sit on my head, let a lone hop up on top. But as a young bunny, Thumper scurried up my arm, shoulder, and head to get away from our German Sheppard.  Most of the time Thumper would sit in a wood and chicken wire hutch, but sometimes got to hop around the living room. After being in the hutch for a week it would take a few minutes of slow walking before Thumper could hop again. The dog's instincts were held in check while Thumper slowly stretched. At the first tentative twitchy hops one hundred thousand years of instinct would flush any domestication from the beasts. Thumper darted down the wall's edge toward the small space under an easy chair. The dog, about two heartbeats behind, focusing only on the furry gray blur, shoulder wedged into the opening. Thumper, changing directions faster than a blink, headed right at me. Sitting cross legged on the carpet, gray dart homing in, I froze, palms on my knees. It was so quick, Thumper had barely touched my hand, arm and shoulder. The dog backed up and turned in time to see me with a bunny sitting on top of my head. The sudden halt to the chase and head tilt seamed to ask, “Master with gray fur laurels, where did bunny go?” From then on the two pets were kept apart just to be safe.

  Thumper started spending more time in the hutch. Caged rabbits spend all their time eating and sleeping. So to make the increasingly larger bunny more comfortable we made a new bigger hutch. One half was wire frame, the other wood. A solid hinged and shingled roof sat on top. A water dish and a rabbit pellet dish were set on the wire side on the cage. Caged rabbits eat a lot, and poop a lot. The wire side of the hutch was intended as the potty side. A tray underneath the wire half's floor was lined with newspaper for easy clean up of droppings. [A side effect of the newspaper tray was that Thumper ended up house broken. In the winter when Thumper got back in the house, any newspaper became the potty spot. The carpet and the hardwood floor were safe as long as the Sunday paper was accessible.] The wooden side of the hutch is very important for an outdoor bunny. They like to have openings that are just big enough to fit though. Thumper would pile up cedar bedding, and droppings, near the opening between the two halves of the hutch. One summer night I found out why.

  I had forgotten to feed Thumper that day, so a few hours after the sun went down I carried the food and water out to the backyard. The yard was lit by a single light bulb by the back door. Its 3000K degree tungsten thread pushed back the night, but not quite to the perimeter of the yard. As I headed to the hutch, my shadow preceded, connecting me to the ink of darkness spilling out of the undergrowth. The hutch sat just under the lowest branches of a big old gnarled hickory tree. This wasn't the first time I had done this, forgotten to feed Thumper, and went out around midnight. But it was the first time I opened the lid of the hutch to see Thumper cowering in the furthest corner from the small opening.
  Thanks to a common evolutionary ancestor and the strength of muscle fiber, all mammals on this planet get about the same number of heartbeats in a lifetime. Small animals like rabbits and mice live shortened lives because their heart rates are so quick. That night, Thumper was burning through weeks of leporidae life.
  Thumper sat stone still in the corner, only the gray furry sides fluttering with each beat and breath. I thought a caress might calm the bunny, but it had no effect. I went about my business, refiling the food and water. One last stroke to try to help, but the same stiff reaction. I lowered the heavy hutch lid on the black night air, leaving Thumper in the darkest part of the hutch. I turned toward the house. A soft swoosh and a ghostly form as wide as a man is tall passed over my head. An owl, wings fully spread, the natural pursuer of rabbits, had taken flight from a branch a foot above my head. In two silent beats of his wings he faded beyond the incandescent gradient.

  When my fright subsided I came to recognize the natural drama I had stumbled into. From the owl's point of view, a plump meal was waiting just inside the box... If only it could use its weapons. For Thumper, silence was the natural defense. “Don't draw attention to yourself, it might not know your here. Listen and don't move, hide until the daylight chases the monster away.” Then I come in an do the last thing a rabbit wants. I open the roof, reveal the pray to the predator. Every second they see each other is a week off the small ones life. The stress unimaginable to me from my position outside of the food chain. Then in an instant, the threat is gone, the lid pushes safety into the darkest corners of the hutch. The monster moved on.


  Thumper lived to be eight years old. That's a pretty long life for a pet rabbit. Thumper is buried under an apple tree not far from the spot where the hutch once stood.

By Lowell Cady – 2011, edited 20200107