将图像从Halcon发送到Python

发布于 2025-02-04 00:15:57 字数 1138 浏览 4 评论 0原文

我想在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟凡古楼 2025-02-11 00:15:57

我只能使用一个循环来加快获取灰色值数据的速度

get_image_size(GrayImage, Width, Height)
tuple_gen_sequence(0, Width - 1, 1, SequenceCols)
Data := []

for Index := 0 to Height - 1 by 1
    tuple_gen_const(Width, Index, SequenceRows)
    get_grayval (GrayImage, SequenceRows, SequenceCols, tempData)
    tuple_concat(Data, tempData, Data)
endfor

I was able to speed up getting gray values data by using only one loop

get_image_size(GrayImage, Width, Height)
tuple_gen_sequence(0, Width - 1, 1, SequenceCols)
Data := []

for Index := 0 to Height - 1 by 1
    tuple_gen_const(Width, Index, SequenceRows)
    get_grayval (GrayImage, SequenceRows, SequenceCols, tempData)
    tuple_concat(Data, tempData, Data)
endfor
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文