How to get and send a CPP Object value?

78 views
Skip to first unread message

Charles Kwon

unread,
Nov 30, 2021, 8:32:06 PM11/30/21
to Harbour Users
Hello All

I tried to Get and sending a CPP object value for OpenCV.
I use hb_retptr() function when get a object pointer.
But, I have no Idea for sending  the object to C function.
My code is like blow:

// prg part

#define IMREAD_COLOR 1

FUNCTION Main()
    LOCAL pImg    
    pImg := cvImread("test.jpg",IMREAD_COLOR )
  //  ?pImg
    INIT_OPENCV( pImg )
   
    ?"OK"

RETURN NIL


/*
 C Part
*/
HB_FUNC( CVIMREAD )
{
  LPSTR lpName = (LPSTR) hb_parc(1);
  int iFlag  = hb_parni(2);  
  Mat image;

  image = imread( lpName, iFlag );
  hb_retptr( &image );
}

HB_FUNC( INIT_OPENCV )
{
 Mat* img = (Mat *) hb_parptr(1);
 Mat image = Mat(* img );     // Is it correct?

//

Please give me a Idea and many thanks!

Regards,
Charles KWON

Charles Kwon

unread,
Dec 1, 2021, 7:37:18 PM12/1/21
to Harbour Users
Hello

I found "Mat"  is very strange and It seems be scope of class object variables.
And I just change code like blow:

HB_FUNC( _CVIMREAD )
{
  LPSTR lpName = (LPSTR) hb_parc(1);
  int iFlag  = hb_parni(2);    
  PHB_ITEM pItem = hb_param( 3, HB_IT_ANY );
  static Mat __img = imread( lpName, iFlag );

  hb_itemPutPtr( pItem, &__img);  
  hb_retptr( &__img );     
  
}


HB_FUNC( CVIMREAD )
{
  LPSTR lpName = (LPSTR) hb_parc(1);
  int iFlag  = hb_parni(2);    
  int iPos   =  hb_parni(3);      
  static Mat image[100] ;
    
  image[iPos] = imread( lpName, iFlag );    
  hb_retptr(  &image[iPos] );  
}



2021년 12월 1일 수요일 오전 10시 32분 6초 UTC+9에 Charles Kwon님이 작성:
Reply all
Reply to author
Forward
0 new messages