将图像从Halcon发送到Python
我想在halcon中拍摄对象的照片,然后将其发送到Python。我将在此处处理图像,并将结果发送回HALCON。到目前为止,我编写/找到了下面的代码,并成功将图像发送到Python。但是,花了很长时间。我听说通过base64发送图像要快得多。你对此一无所知吗?
Protocol := 'TCP4'
Timeout := 100.0
#Open a socket connection
open_socket_connect ('192.168.20.155', 60000, ['protocol','timeout'], [Protocol,Timeout], Socket)
get_socket_param (Socket, 'address_info', Address)
#To is not evaluated for TCP and connected UDP sockets
To := []
read_image (Image, 'printer_chip/printer_chip_01')
#Make sure we have only one channel
rgb1_to_gray (Image, GrayImage)
get_image_pointer1 (GrayImage, _, _, Width, Height)
RowIndexes := []
for j:=0 to Height-1 by 1
tuple_gen_const (Width, j, TempIndexes)
RowIndexes := [RowIndexes,TempIndexes]
endfor
ColIndexes := []
tuple_gen_sequence (0, Width-1, 1, Sequence)
for i:=0 to Height-1 by 1
ColIndexes := [ColIndexes,Sequence]
endfor
#get pixel values
get_grayval (GrayImage, RowIndexes, ColIndexes, Data)
#C: one byte = 8 bit, Unsigned
Format := 'C' + Width*Height
send_data (Socket, Format, Data, To)
receive_data (Socket, 'z', Answer, From)
stop ()
close_socket (Socket)
I want to take a picture of an object in HALCON and send it to Python. I will process the image there and send the result back to HALCON. So far, I wrote/found the code below and was successful to send the image to Python. However, it took so long time. I heard that sending an image via base64 is much faster. Do you know anything about that?
Protocol := 'TCP4'
Timeout := 100.0
#Open a socket connection
open_socket_connect ('192.168.20.155', 60000, ['protocol','timeout'], [Protocol,Timeout], Socket)
get_socket_param (Socket, 'address_info', Address)
#To is not evaluated for TCP and connected UDP sockets
To := []
read_image (Image, 'printer_chip/printer_chip_01')
#Make sure we have only one channel
rgb1_to_gray (Image, GrayImage)
get_image_pointer1 (GrayImage, _, _, Width, Height)
RowIndexes := []
for j:=0 to Height-1 by 1
tuple_gen_const (Width, j, TempIndexes)
RowIndexes := [RowIndexes,TempIndexes]
endfor
ColIndexes := []
tuple_gen_sequence (0, Width-1, 1, Sequence)
for i:=0 to Height-1 by 1
ColIndexes := [ColIndexes,Sequence]
endfor
#get pixel values
get_grayval (GrayImage, RowIndexes, ColIndexes, Data)
#C: one byte = 8 bit, Unsigned
Format := 'C' + Width*Height
send_data (Socket, Format, Data, To)
receive_data (Socket, 'z', Answer, From)
stop ()
close_socket (Socket)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我只能使用一个循环来加快获取灰色值数据的速度
I was able to speed up getting gray values data by using only one loop