Recent

Author Topic: Morphing on a Square Mesh: Working Matrix Version (Horray!)  (Read 719 times)

Boleeman

  • Hero Member
  • *****
  • Posts: 781
Morphing on a Square Mesh: Working Matrix Version (Horray!)
« on: October 25, 2024, 06:07:27 pm »
I tried to convert some VBNet code that performs morphing using a square mesh.

Got the loading of the images and the mesh working.
Got the saving of the mesh points working.
Bmps saved after btnMorph click


Not working:

Moving the control points
The morphed bmps don't show the morphing correctly.


Ah, headaches over this one !

« Last Edit: October 26, 2024, 08:42:44 pm by Boleeman »

DomingoGP

  • Jr. Member
  • **
  • Posts: 80
Re: Morphing on a Square Mesh using TBgrabmp
« Reply #1 on: October 26, 2024, 11:51:57 am »
Fix for moving control points (barely tested) note the var parameters r and c

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FindControlPoint(index, X, Y: Integer;var  r, c: Integer);
  2. var
  3.   dx, dy: Single;
  4. begin
  5.   r:=0;
  6.   while r < NUM_POINTS do
  7.   begin
  8.     c:=0;
  9.     while c < NUM_POINTS  do
  10.     begin
  11.       dx := Abs(m_Point[index, r, c].X - X);
  12.       dy := Abs(m_Point[index, r, c].Y - Y);
  13.       if (dx < POINT_WID - 1) and (dy < POINT_WID - 1) then
  14.         Exit;
  15.       inc(c)
  16.     end;
  17.     inc(r);
  18.   end;
  19.  
  20.   r := -1;
  21.   c := -1;
  22. end;  
  23.  

TRon

  • Hero Member
  • *****
  • Posts: 3946
Re: Morphing on a Square Mesh using TBgrabmp
« Reply #2 on: October 26, 2024, 11:58:57 am »
As mentioned by DomingoGP, all byref's in the original basic code should be a var parameter in pascal.

Thus also for method STToPoints and function PointsToST.
« Last Edit: October 26, 2024, 12:08:42 pm by TRon »
I do not have to remember anything anymore thanks to total-recall.

Boleeman

  • Hero Member
  • *****
  • Posts: 781
Re: Morphing on a Square Mesh using TBgrabmp
« Reply #3 on: October 26, 2024, 03:10:05 pm »
Brilliant DomingoGP and TRon.

Thanks for the fixes to moving the points.


Now trying to work out why the rendered bmp are not rendering the morphed pictures properly.

Looking at the bmps, there seems to be a triangular part which shouldn't be there.
The VBNet code used clone to copy the pixels, whereas I am using draw to white background
 
m_Bm[2] := TBGRABitmap.Create(m_Bm[0].Width, m_Bm[0].Height, clWhite);
  m_Bm[2].Draw(m_Bm[0].Canvas, 0, 0, True);

Also I used the TBgrabmp MergeBGRA to merge the morphed pixels:
m_Bm[2].SetPixel(x, y, MergeBGRA(AColor, Round((1 - fraction) * 255), BColor, Round(fraction * 255)));

Perhaps something here is a bit off ?

Not sure if circular might have any idea on the morphed render anomaly ?




« Last Edit: October 26, 2024, 03:14:35 pm by Boleeman »

Boleeman

  • Hero Member
  • *****
  • Posts: 781
Re: Morphing on a Square Mesh using TBgrabmp: Rendered Bmp Problem
« Reply #4 on: October 26, 2024, 08:37:40 pm »
I was also working on another version that uses Matrices, written in Delphi by some French Programmer.
Contains a really good (High End) Matrix Unit.

Finally got it working so here it is.

It loads jpg on start up. Would be nice to convert to Bgrabmp.
On startup it loads 2  jpg pictures and their corresponding mesh points (Need to have these in the startup folder)

The difficulty with the conversion came in getting the ReShape procedure to overlay the grid of TShape dots over the loaded jpg. After many attempts I realized that the TPanels were giving an "index(1) out of bounds error" even thought that did not happen with the Delphi version. The initial conversion was also making the dots disappear each time one was clicked in the Lazarus version.

Also perhaps I wonder if someone could possibly add a save to Anigif or Apng (Not entirely sure how to do it)

Lastly needed to mention that "When you click GO to do a Morph it takes a while and then the magic happens"

Anyhow. Enjoy.
« Last Edit: October 27, 2024, 04:50:55 am by Boleeman »

 

TinyPortal © 2005-2018