Cpp 2 PB translation but understanding

Just starting out? Need help? Post your questions and find answers here.
User avatar
Olliv
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Sep 22, 2009 10:41 pm

Re: Cpp 2 PB translation but understanding

Post by Olliv »

What does say the specific doc about the third argument of dNoise() function? Is the unit in bytes really? (not in quads?)
LiK137
Enthusiast
Enthusiast
Posts: 282
Joined: Wed Jun 23, 2010 5:13 pm

Re: Cpp 2 PB translation but understanding

Post by LiK137 »

...
Last edited by LiK137 on Wed May 10, 2017 11:19 pm, edited 1 time in total.
LiK137
Enthusiast
Enthusiast
Posts: 282
Joined: Wed Jun 23, 2010 5:13 pm

Re: Cpp 2 PB translation but understanding

Post by LiK137 »

Posting new modified minimalistic code for better understanding
Last edited by LiK137 on Thu May 18, 2017 4:42 pm, edited 1 time in total.
User avatar
Olliv
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Sep 22, 2009 10:41 pm

Re: Cpp 2 PB translation but understanding

Post by Olliv »

(I add message references as A1, A2, etc... to help us a little bit). Do not hesitate to write these references to grow time.

A1)

Code: Select all

RET = FSDK_FeedFrame(Tracker, 0, imageHandle,
@FaceCount, @*IDs, MaXize):ErrorDCode(RET, #PB_Compiler_Line)
;MemorySize(*IDs) MaXize maximum 256 faces detected
Debug @*IDs
ShowMemoryViewer(@*IDs,MaxSize)
I can see 2 names : MaXize and MaxSize. Why?

A2) I can see a temporary variable named Count.
I suggest you to choose one name per using, even if it is temporary :
CameraQty
VideoFormatQty
(Qty or Count or other : main is you grow your handling)

A3)

Code: Select all

RET = FSDK_GetAllNames(Tracker, *IDs, @Name,
256):ErrorDCode(RET, #PB_Compiler_Line) ; maximum of 256
characters ; *IDs\IDs[1] ; @*IDs\IDs[1]
Here I can see comment I suppose some checking.
First element is zero index
; *IDs\IDs[0] ; @*IDs\IDs[0] (value and address of 1st cell)

A4) We can say assertion error is a "big" problem as a zero where an address is expected. Or a wrong address, etc... It's a value far away of its normal domain. And if you can see such this error occuring, the reason is, often because a single character typing is too much or too less. I suggest you to use the apokaliptic directive named EnableExplicit. It's like Freddy Mercury in pink dress which sings he wants to breakfree : at the beginning, you can become crazy, but once everything is defined, a typing mistake is unabled and let you mind freely to test deeper problems as the choice of a value, address or address of address in an argument of external function.

A5) I prefer precise I just have a Smartphone and slow network and it is unabled to download and test whole or consequent system. It is a public call if other have this availability, even if I think you will find step after step the good solution. I can test sometimes parts of code I copy and transmit to computers I meet on my way, but no more. I can help you but I have material limits.
User avatar
Olliv
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Sep 22, 2009 10:41 pm

Re: Cpp 2 PB translation but understanding

Post by Olliv »

A6)

For dNoise() function, my question about the 3rd argument is : Are we sure the unit expected is in bytes or in quads?

If dNoise() function expects quads, we give it a too big value (8 times), because I considered the unit expected was the byte. Can you confirm?

If I was false, perhaps the same error converting is to update in other places.
User avatar
Olliv
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Sep 22, 2009 10:41 pm

Re: Cpp 2 PB translation but understanding

Post by Olliv »

A7)

Code: Select all

NullCharacterPos = FindString(Name, Chr(0))
If (NullCharacterPos > 0)
Name = Left(Name, NullCharacterPos - 1)
EndIf
Here, I suppose you delete the last character of the name.
If string format does not bring problems between PureBasic string libraries and these external functions, you can use this :

Code: Select all

Name = Trim(Name)
(Which removes all spaces over a string expression)
and use

Code: Select all

Name = Left(Name, Len(Name) - 1)
(which force to remove the last character)

I tell you that because until Pb version 5.50, FindString(SomeOne$, Chr(0) ) will ever return 0 whatever the content of the string SomeOne$. I do not think it's changed since.
You can search all the characters you want with FindString excepted the string null terminated character (chr(0) ) which represents "" (a null string, nothing, etc...).
LiK137
Enthusiast
Enthusiast
Posts: 282
Joined: Wed Jun 23, 2010 5:13 pm

Re: Cpp 2 PB translation but understanding

Post by LiK137 »

Hi,

Very good to C U again :)

regarding A1:
- FSDK_FeedFrame is the main headache for me.
Cpp syntax according2doc

Code: Select all

int FSDK_FeedFrame(HTracker Tracker, long long CameraIdx, 
HImage Image, long long * FaceCount, long long * IDs, long 
long MaxSizeInBytes);
Tracker – handle of the tracker in which to process the frame.
CameraIdx – index of the camera; should be equal to 0 in the current release.
Image – the HImage handle of the video frame to process.
FaceCount – address of the 64-bit integer value that will receive the count of faces tracked
in the current frame.
IDs – address of the array of 64-bit integer values that will receive the identifiers of the
tracked faces.
MaxSizeInBytes – amount of memory allocated for the IDs array.

Structures I use in the PBrocedure

Code: Select all

Structure TPoint                ;- FaceFeatStruct    .TPoint(#FSDK_FACIAL_FEATURE_COUNT - 1)
  x.l
  y.l
EndStructure

Structure TFacePosition   ;- FacePoStruct.TFacePosition(#TFPositionz)   ; Obzervd Long is bit faster than Int
  xc.l
  yc.l
  w.l
  padding.l
  angle.d
EndStructure

Structure FSDK_VideoFormatInfo   ;- WebcamStruct
  Width.l
  Height.l
  BPP.l
EndStructure

Structure VideoFormatInfo
  VideoFormatInfo.FSDK_VideoFormatInfo[255]
EndStructure  

Structure CameraList
  CameraList.s[255]
EndStructure  

Structure IDs
  IDs.i[255]
EndStructure  
It was almost morning and I was sleepy when copypaste showmemory from other procedure (copypaste problem:) ThanQ very much to mention MaXize and MaxSize and they hold same value.


A2: Got it and will try to not forget

A3: Yes, I have tried without index, with [0] - 1st and [1] - 2nd element.
ShowMemoryViewer shows odd elements always equal. I walked memory 8 bytes and
saw always [0]=[2]... and [1]=[3]... but not applicable to next FSDK function that using IDs

A4: I have read about assertion to disable dial.box and as You mentioned saw it has to be fixed and
not omit. This raises exclusively in FSDK_FeedFrame when using @*IDs as according 2 documentation
IDs – address of the array of 64-bit integer values that will receive the identifiers of the
tracked faces. But if we use *IDs then no assertion warning but this time invalid argument as address
required.
Too much work for Detective EnableExplicit now but going to.
A5: ThanQ so much, I understand it is almost impossible to test everything.

A6: dNoise expects Quad (I always Used Int instead of Quad but You better know)

A7: Very important notice, I didn't know, Thanx


I am very upset with the FeedFrame as Cpp, C#, VB6, VB.Net, Delphi all of them compiles with no error but
PureBasic raises Assertion.

What is wrong, I don't understand, with:

Code: Select all

RET = FSDK_FeedFrame(Tracker, 0, imageHandle, @FaceCount, @*IDs, MaXize)
User avatar
Olliv
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Sep 22, 2009 10:41 pm

Re: Cpp 2 PB translation but understanding

Post by Olliv »

A8)
Very important in your way to use EnableExplicit. Even if you started without, what it causes difficulties for you to readapt all undefined variables.

I suggest you too to replace "Protected" with "Define" (same executing result) which simplify tests inside and outside a procedure. Also, you will not have to rewrite all your definitions when you move a code part into a procedure, or from a procedure.

A9)

Code: Select all

RET = FSDK_FeedFrame(Tracker, 0, imageHandle, @FaceCount, @*IDs,
MaXize)
1) 5th arg : remove '@' character
2) 6th arg : change to right syntax

Code: Select all

RET = FSDK_FeedFrame(Tracker, 0, imageHandle, @FaceCount, *IDs,
MaxSize)
*IDs is the address of the array

@*IDs is the address of the address of the array and doesn't match to the doc definition you copied below.

This last syntax is useful when a function will provide you an array, and so its new address.
User avatar
Olliv
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Sep 22, 2009 10:41 pm

Re: Cpp 2 PB translation but understanding

Post by Olliv »

A10) I am surprised by the types I can read inside the structures you have published.

Code: Select all

Structure TPoint
x.l
y.l
EndStructure
Structure TFacePosition
xc.l
yc.l
w.l
padding.l
angle.d
EndStructure
Structure FSDK_VideoFormatInfo ;- WebcamStruct
Width.l
Height.l
BPP.l
EndStructure
Structure VideoFormatInfo
VideoFormatInfo.FSDK_VideoFormatInfo[255]
EndStructure
Structure CameraList
CameraList.s[255]
EndStructure
Structure IDs
IDs.i[255]
EndStructure
Are these structures required by external functions, or are they just used by your own pb procedures.

If it is required, I doubt about right types. (Long 32 bits or Quad 64 bits).
LiK137
Enthusiast
Enthusiast
Posts: 282
Joined: Wed Jun 23, 2010 5:13 pm

Re: Cpp 2 PB translation but understanding

Post by LiK137 »

ThanQ very much.
I changed Longs to Quad but now while the error still remains this time working functions stopped working.
I returned back to Long.

Code: Select all

            RET = FSDK_FeedFrame(Tracker, 0, imageHandle, @FaceCount, *IDs, MaXize)
Reports Invalid argument

Code: Select all

            RET = FSDK_FeedFrame(Tracker, 0, imageHandle, @FaceCount, @*IDs, MaXize)
            RET = FSDK_GetTrackerFacePosition(Tracker, 0, *IDs\IDs[i], @*facePosition)
is OK but with Assertion and *facePosition\xc (yc, w) always 0
User avatar
Olliv
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Sep 22, 2009 10:41 pm

Re: Cpp 2 PB translation but understanding

Post by Olliv »

A11)

At the base, there was two errors in the same line. : *Id and MaxSize. If we cut only one of them, the goal won't be reached !

Code: Select all

RET = FSDK_FeedFrame(Tracker, 0, imageHandle,
@FaceCount, *IDs, MaxSize)
I apologize insisting but it's MaxSize, not MaXize.

I am boring, sometimes !! :mrgreen:

Could you confirm you have a problem with this right syntax?

A12)
Lik137 wrote:A6: dNoise expects Quad (I always Used Int instead of Quad but You better know)
Actually, we have this :

Code: Select all

dNoise(hAudio, *pitch, MemorySize(*pitch) )
MemorySize() gives a quantity of bytes.

My question is "Is the byte the good unit?"

In example, if you find in the doc, dNoise() expects a quantity of quads, a fix must be done like that:

Code: Select all

dNoise(hAudio, *pitch, MemorySize(*pitch) / 8)
The division converts a quantity a bytes to a quantity of quads.

Also, "quads", "bytes", "address of address" : I understand your headaches !!
LiK137
Enthusiast
Enthusiast
Posts: 282
Joined: Wed Jun 23, 2010 5:13 pm

Re: Cpp 2 PB translation but understanding

Post by LiK137 »

Hi Olliv,
Its just pleasure to C Ur replies.

A11: changed MaxIze to MaxSize
still Assertion
*IDs doesn't return right ID values and reports incorrect Argument problem
while @*IDs returns correct IDs with Assertion (1st discovered face is *IDs\IDs[0]=1, 2nd face
is 2 and each next discovered face is +1 so in frame if there are n faces then *IDs\IDs[n<=255]=n


A11.1: RET = FSDK_GetTrackerFacePosition(Tracker, 0, *IDs\IDs, @*facePosition)
reports correct argument syntax but *facePosition\xc (yc, w) always 0 but correct face coordinates
should be poke to @*facePosition address)

there are 2 problems remaining:
Pr1: Assertion which is only in FSDK_FeedFrame line. I put debug/messagerequester
before and after the line and before 2nd debug assertion release.

Pr2: Correct Face coordinates to *facePosition.TFacePosition


A12: Let me test MemorySize(*pitch) / 8 and back with result
User avatar
Olliv
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Sep 22, 2009 10:41 pm

Re: Cpp 2 PB translation but understanding

Post by Olliv »

Lik137 wrote:A12: Let me test MemorySize(*pitch) / 8 and back with result
Hoping my forget of this dividing is the reason for crash.

A13)
Lik137 wrote:A11.1: RET = FSDK_GetTrackerFacePosition(Tracker, 0, *IDs\IDs, @*facePosition)
reports correct argument syntax but *facePosition\xc (yc, w) always 0 but correct face
coordinates
should be poke to @*facePosition address)
there are 2 problems remaining:
Pr1: Assertion which is only in FSDK_FeedFrame line. I put debug/messagerequester
before and after the line and before 2nd debug assertion release.
Pr2: Correct Face coordinates to *facePosition.TFacePosition
This answer indirectly to my question #A10 ("Are the structures required by external functions set?") : These structures are well required...

So, I think you have unhappily not the choice between longs (32 bits int) and quads (64 bits int) inside required structures.

Plus, I can see floating fields are 64 bits sized in many structures.

Code: Select all

Structure TFacePosition
   xc.l ; 32 bits
   yc.l ; 32 bits
   w.l ; 32 bits
   padding.l ; 32 bits
   angle.d ; 64 bits
EndStructure
I am puzzled by this blend of two different types : 32 bits and 64 bits.
Perhaps a fix :

Code: Select all

Structure TFacePosition
   xc.Q
   yc.Q
   w.Q
   padding.Q
   angle.D
EndStructure
Hoping this 64 bits structure above deletes some bugs.

In this way only, and if you want to keep 32 bits types for integer fields, I imagine this intermediate structure :

Code: Select all

Structure TFacePosition
   xc.L
   useless0.L
   yc.L
   useless1.L
   w.L
   useless2.L
   padding.L
   useless3.L
   angle.D
EndStructure
Useless fields have only two values : 0 or -1 depending of the sign of their low neighboured 32 bits long value (xc for useless0, yc for useless1, etc...).

There is only 2 external function flow : to them, and from them.

To external function flow : useless fields must be set.

From external function flow : ne need to check useless field because the sign of each value is in the bit 31.

A simplifying context is have ever positive values, or have ever negative values.
User avatar
Olliv
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Sep 22, 2009 10:41 pm

Re: Cpp 2 PB translation but understanding

Post by Olliv »

Lik137 wrote:I changed Longs to Quad but now while the error still remains this time working functions
stopped working.
I returned back to Long.
Have you got really same errors at the same lines, and same returned values ?

If no exactly same, please choose quads (or couple of 2 longs - with "useless" fields).
LiK137
Enthusiast
Enthusiast
Posts: 282
Joined: Wed Jun 23, 2010 5:13 pm

Re: Cpp 2 PB translation but understanding

Post by LiK137 »

C Next page
Last edited by LiK137 on Thu May 18, 2017 4:43 pm, edited 1 time in total.
Post Reply