Halcon/HDevelop socket send generic image data

Halcon Progress 20 provides sockets for different protocols (HALCON, UDP, TCP) and the send_data(Socket, Format, Data, To) procedure to send arbitrary data. How can this procedure be used to send an image from hdevelop to another connected socket?

The Halcon Solution Guide on Programmed Visualization states the following:

Sometimes it might be necessary not to apply the standard HALCON visualization operators, but to use a selfprogrammed version. This can be achieved by using the access functions provided for all data types. Examples for these are get_image_pointer1, get_region_runs, or get_contour_xld. Operators like these allow full access to all internal data types. Furthermore, they provide the data in various forms (e.g., runlength encoding, points, or contours) to make further processing easier. Based on this data, a self programmed visualization can be developed easily.

Here is a basic example of how I think this should work:

read_image (Image, 'printer_chip/printer_chip_01')

* Send image via socket
Protocol := 'TCP4'
Timeout := 5.0
* Open a socket connection
open_socket_connect ('', 5000, ['protocol','timeout'], [Protocol,Timeout], Socket)
* To is only used with protocol HALCON or UDP (empty for bound TCP connections)
To := []
* The following send_data is working, the connected socket receives this message
send_data (Socket, 'z', ['Generic sockets are great!'], To)

* Make sure we have only one channel
rgb1_to_gray (Image, GrayImage)
get_image_pointer1 (GrayImage, Pointer, Type, Width, Height)

* get_image_pointer returns pointer of type 'byte' -> use a byte format specifier for socket
* c: one byte = 8 bit, signed
* Append the type specifier with a number for a repeat count, e.g. 'c5' means 'ccccc'
Format := 'c' + Width*Height
* Format := 'c'
* How to cast the raw pointer correctly to send the data it points to?
send_data (Socket, Format, [Pointer], [])

The final line send_data (Socket, Format, [Pointer], []) throws an exception:

Unhandled program exception:

HALCON operator error while calling 'send_data' in procedure 'main' line: 78.

Format specification does not match the data (HALCON error code: 5628)

Obviously the Pointer is the address pointing to where the image is in memory and not the actual data which probably leads to the error.

Is there a way to cast the raw pointer correctly in HDevelop to send it via the socket? Or can this only be done in an external C/C++/C# application using the Halcon libraries?

The Halcon documentation on gen_image_pointer1 provids only this C example:

Hobject  Image;
char     typ[128];
Hlong     width,height;
unsigned char *ptr;


I would like to use the features of HDevelop and not use the sockets in C/C++/C# (although this would be another way). The only thing missing is to actually send the image from within HDevelp to receiving sockets.

Read more here: https://stackoverflow.com/questions/64893249/halcon-hdevelop-socket-send-generic-image-data

Content Attribution

This content was originally published by evolved at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: