Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 20:31 24 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : PicoMite Thermal Camera

     Page 2 of 4    
Author Message
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4222
Posted: 08:26am 06 Jun 2024
Copy link to clipboard 
Print this post

Peter, Daniel,

I think I found a way to use the BOX command and still remain within the memory constraints. Not shaving any more bytes out of the code, but a different approach.

I am going to plot the even pixels, using a half size array for x() and y().
Then in a second pass I will plot the odd pixels, using the same half size arrays.
In stead of 2 arrays 22kbyte in size there will be 2 arrays 11kb in size.

I will have to split the color array in 2, but that is only few MATH commands, and total size (kbyte) will not change.

This may not transpire into 21ms, but should be below 100ms total (from 350ms).
So we would be below 500ms (essential to align with the sensor 2Hz update rate).

Looking forward to the BOX command with scalars for w and h.

Volhout

EDIT: it actually takes only 23ms to do two-pass screen write using BOX statements.
Edited 2024-06-06 20:19 by Volhout
PicomiteVGA PETSCII ROBOTS
 
Amnesie
Guru

Joined: 30/06/2020
Location: Germany
Posts: 396
Posted: 11:35am 06 Jun 2024
Copy link to clipboard 
Print this post

Volhout,

Thank you for the hint with I2C, since I am going to use the SYSTEM I2C.
The thermal camera is on its way and I can't wait to try it. I ordered local here in Germany, so I hope it arrives till the weekend.

I guess for your latest version I need to update to Peters latest beta version, but that's not a problem.

So many things which can be done with this thermal camera, maybe a human presence detector.

Do you have made this program with something special in mind? Would be interesting to hear, for what usecase you bought it  

Greetings
Daniel
Edited 2024-06-06 21:35 by Amnesie
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4222
Posted: 12:29pm 06 Jun 2024
Copy link to clipboard 
Print this post

Daniel,

A bit of a problem. To make the averaging fast with MATH M_MULT statements I am using 2D arrays.

However, the BOX command only accepts 1D arrays. I have everything coded up, including an array for w and h in the BOX statement, and now I run into this last hurdle. And I know of no fast method to convert a 2D array into a 1D array (except FOR-NEXT). And regardless, no RAM left for both arrays.

Technically I could use the MATH_MULT statement to scale up to a 1D array, but that would require huge conversion matrices.

Back to the drawing board.....

Volhout
PicomiteVGA PETSCII ROBOTS
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9108
Posted: 01:54pm 06 Jun 2024
Copy link to clipboard 
Print this post

You can copy a 2d array into a 1d array using the math slice command
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4222
Posted: 08:26pm 06 Jun 2024
Copy link to clipboard 
Print this post

Hi Peter,

I tried, but it eludes me how I can perform this function in one or more MATH SLICE commands.


+-    -+     +-          -+
| a  b | --> | a  b  c  d |
| c  d |     +-          -+
+-    -+


Please suggest a solution.

In essence I have it working now with an array for w and h (there is enough memory after all the crunching) but there is still some time to gain.
I am around 610ms per loop, and need it to become below 500ms.

One thing I stumbled upon is that you can do linear interpolation on temperatures, and also do linear interpolation on color index, but not on color (i.e. &hff4000). So in the end I need to translate (pixel for pixel) the color index to the color. Since the BOX command does not work with color indexes, but with RGB values.

So I can speed up all the math as much as I like, but the translation to RGB value has to happen on a pixel basis(*). And that is the main remaining delay in the plot function.

Regards,

Volhout

(*) a pixel is a 5x5 box with uniform color
The source (camera) is 16x12 pixels, so all complex conversions can better be done on these 192 elements, rather than the up-scaled 2790 elements. That is why RGB conversion takes so much time, and there is no MATH command (or set of MATH commands) that can do this for me, it must be in a loop.
for i=0 to max
array(i)=color%(array(i))
next

Edited 2024-06-07 06:37 by Volhout
PicomiteVGA PETSCII ROBOTS
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4222
Posted: 07:45am 07 Jun 2024
Copy link to clipboard 
Print this post

Peter,

With some tuning I managed to get it down to 590ms on the VGA unit.
Further squeezing may be possible by combining some matrix math, but that will require the scalars in the BOX command (since I need some RAM for another 2D array).

It is irony that the sensor pixel voltages are in a 1D array, that needs conversion to a 2D array to do the matrix math. After doing the matrix math, we have to convert back to a 1D array for the BOX command. Technically it is possible to do the matrix math directly from a 1D array to a 1D array, but that requires a conversion array(2D) size 192 x 2790 consuming 4Mbyte of RAM.

But still, the index->RGB value is the one thing I cannot do in MATH statements, and is the biggest bottleneck right now. A MATH INDEX command could help.

I think I am exceeding my credit limit right now....
- scalars for w and h in the BOX command
- a solution to converting 2D to 1D and vice versa (MATH SLICE / INSERT howto)
- MATH INDEX ?

Please raise the RED flag when I ask too much..

Regards,

Volhout
Edited 2024-06-07 17:56 by Volhout
PicomiteVGA PETSCII ROBOTS
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6097
Posted: 08:20am 07 Jun 2024
Copy link to clipboard 
Print this post

  Quote   a solution to converting 2D to 1D and vice versa (MATH SLICE / INSERT howto)


 '
 OPTION EXPLICIT
 OPTION DEFAULT INTEGER
 DIM twod(2,2)
 DIM oned(8)
 DIM n,k
 FOR n = 0 TO 8
   oned(N) = 10+n
 NEXT n
 
 MEMORY COPY INTEGER PEEK( VARADDR oneD()),PEEK( VARADDR twoD()),9*8
 
 FOR n = 0 TO 2
   FOR k = 0 TO 2
     PRINT "twoD(";k;",";n;") ";twoD(k,n)
   NEXT k
 NEXT n



RUN
twoD( 0, 0)  10
twoD( 1, 0)  11
twoD( 2, 0)  12
twoD( 0, 1)  13
twoD( 1, 1)  14
twoD( 2, 1)  15
twoD( 0, 2)  16
twoD( 1, 2)  17
twoD( 2, 2)  18
>


Provided the row/column order is suitable.

Jim
Edited 2024-06-07 18:21 by TassyJim
VK7JH
MMedit   MMBasic Help
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9108
Posted: 10:20am 07 Jun 2024
Copy link to clipboard 
Print this post

Harm

Try the attached


PicoMite.zip

Check the new command specially for you  

CLS
Dim x%(3)=(0,10,20,30),y%(3)=(0,10,20,30)
Dim w%(3)=(10,10,10,10),h%(3)=(10,10,10,10)
Box x%(),y%(),w%(),h%(),1,RGB(red),RGB(green)
Pause 1000
CLS
Box x%(),y%(),10,10,1,RGB(blue),RGB(yellow)
Dim c%(15),m%(15)
For i=0 To 15:c%(i)=i:Next
Colour Map c%(),m%()
For i=0 To 15
Print c%(i),Hex$(m%(i))
Next


NB: input and output array can be the same
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4222
Posted: 01:25pm 07 Jun 2024
Copy link to clipboard 
Print this post

Hi Peter,

Will look into it during the weekend. I am external right now.
Am I right that the colour map command maps to the pre-defined colour map. Not user defined in a col%() array.
I had pre-arranged the colours to aligh with the human temperature guts (red=warm = high index, blue = cold is low color index, white is hottest = index 15

Volhout
Edited 2024-06-07 23:29 by Volhout
PicomiteVGA PETSCII ROBOTS
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4222
Posted: 02:12pm 07 Jun 2024
Copy link to clipboard 
Print this post

@Peter,

The COLOUR MAP works, but as I discovered, they are the pre-defined colours. It would be nice to customize them.

The scalars for w and h in the BOX command work !!
The MEMORY COPY trick TassyJim proposed works great. Only in the example , the copy should be 9, not 9*8.

The complete screen draw routine takes 97ms now (from 350ms), and the refresh rate is determined by the thermo sensor speed now. This means we do not mis frames anymore.
On the VGA verion I currently run without framebuffer, so there is some flashing on screen that I have to work on.

Then I will work on the functions, like logging and such.

Thank you all for your cooperation. Next week I will continue the project. This weekend is claimed by my family.

Volhout
Edited 2024-06-08 00:14 by Volhout
PicomiteVGA PETSCII ROBOTS
 
Amnesie
Guru

Joined: 30/06/2020
Location: Germany
Posts: 396
Posted: 09:55am 08 Jun 2024
Copy link to clipboard 
Print this post

Volhout,

the thermal module arrived and your sorftware works geat, just impressive!  

Me sitting in front of the cam holding the smartphone to shoot the image:




I am excited to see how far you can push it to the limits, but to be honest, I am really happy with the current results.


Greetings
Daniel
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3150
Posted: 11:42am 08 Jun 2024
Copy link to clipboard 
Print this post

Wow. Really impressive to see the photo. Can't wait for the ILI9341 version.

Ok. Time to order the module. My 180-year-old house can use some weatherizing upgrades.
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4222
Posted: 01:43pm 08 Jun 2024
Copy link to clipboard 
Print this post

Daniel,

You are running 378Mhz. The version I listed here does 730ms at 252Mhz.

The version under development now achieves 500ms at 252Mhz. This is for compatibility with the Game*Mite.

The number 511 in the top corner is the speed. The camera module speed is 500ms approximately.So you run in sync with the camera now. The number will never be less than this, since the software will wait until the camera Has a new frame ready

Volhout
Edited 2024-06-08 23:50 by Volhout
PicomiteVGA PETSCII ROBOTS
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9108
Posted: 05:24pm 08 Jun 2024
Copy link to clipboard 
Print this post

Harm

One last change


PicoMite.zip


You can now specify the colours that numbers 0 to 15 will map to in the COLOUR MAP command

COLOUR MAP inarray%(), outarray%() [,colourmap%()]

colourmap%() is an array that must be 16 elements long and will contain values in the range 0 to &HFFFFFF. If this optional array is specified then the number in inarray%() will be mapped using this array. If colourmap%() is not specified then the standard RGB121 colour mapping will be used.
 
Quazee137

Guru

Joined: 07/08/2016
Location: United States
Posts: 567
Posted: 05:49pm 08 Jun 2024
Copy link to clipboard 
Print this post

Volhout

 Wondering if this would catch my hot water pipes in the wall. I am getting
ready to lose my tank type water heater for a few smaller tankless ones.
Mapping out where the pipes are would be useful.

Could this be done as a remote hand held device and have it send the data
to the PicoMite making a log file for later review?

I could scan each wall/floor and view later.

Thanks for all the work your doing.
Quazee137
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4222
Posted: 09:15pm 08 Jun 2024
Copy link to clipboard 
Print this post

It can clearly identify whete wxactly  in the bezel pf a laptop screen the  aclight driver is mounted. So I ecpect it can find warmer parts of a wall.
PicomiteVGA PETSCII ROBOTS
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 2120
Posted: 09:26pm 08 Jun 2024
Copy link to clipboard 
Print this post

a rad and hidden pipes. ready made 32x24 camera mlx90640 wide

 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4222
Posted: 07:50am 09 Jun 2024
Copy link to clipboard 
Print this post

Hi Peter,

I quickly tried your latest version, with user color matrix in the COLOUR MAP.
It works well for a while, but then throws an error that I cannot explain. Below shows the min and max indexes used in the color array. The array is static DIM col%(15). I have no explantion of the below error message.

This is PicoMite (non VGA).

 38K (23%) General
 35K (23%) Free
14     0
15     0
14     0
14     0
15     0
14     0
14     0
14     0
15     0
15     0
15     0
15     0
15     0
14     0
14     0
[36] Colour Map scrn_1De(),scrn_1De(),col%()
Error : Dimensions
> ?math(max scrn_1de())
14
> ?math(min scrn_1de())
0
>  


Volhout
PicomiteVGA PETSCII ROBOTS
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4222
Posted: 07:54am 10 Jun 2024
Copy link to clipboard 
Print this post

Peter,

With the last addition (of the custom color map) you introduced strange behaviour.
The version with the fixed colormap was stable.
The version with the custom color map is not. I get error messages like Array size mismatch, and as in previous shown Error: Dimensions.

These errors also show when I do not use the custom color map, just use the build in map.

In the VGA version the message Error: Array dimensions is far dominant, in the PicoMite non-VGA the Error: Dimensions is the only one error message.
In case it is memory related: the VGA version has 41kbyte free, the non VGA has 35kbyte free (uses framebuffer) but has only 2kbyte that can be used for MMBasic data. When I add a 2kbyte size array it still works, but with 4 kbyte there are "out of memory" error messages.

If there is anything you want me to test, please let me know....

Volhout

After somemore testing I think it is a memory leak. Since the non-VGA version shows it almost directly, and the VGA (more memory free) shows it after a minute or so. RC5 behaves the same.
Edited 2024-06-10 18:19 by Volhout
PicomiteVGA PETSCII ROBOTS
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4222
Posted: 09:07am 10 Jun 2024
Copy link to clipboard 
Print this post

Hi Peter,

Short test program (Picomite VGA)

dim dummy(10000)
dim a(1000)
dim b%(15)'=(0,255,0,255,0,255,0,255,0,255,0,255,0,255,0,255)

memory

n=0
do
 inc n:print n
'  for i=0 to 1000:a(i)=int(15*rnd()):next
 for i=0 to 1000:a(i)=15*rnd():next
'  colour map a(),a()
 colour map a(),a(),b%()
loop


The program stops after x iterations. Using integers, seems a bit more robust. No difference between internal color map and external color map.
Tested on RC5.

Volhout
Edited 2024-06-10 19:08 by Volhout
PicomiteVGA PETSCII ROBOTS
 
     Page 2 of 4    
Print this page
© JAQ Software 2024