Octave, display image received by socket connection does't show

折月煮酒 提交于 2019-12-11 04:55:01

问题


I have an octave script in which i open a socket server an receive some commands from connected clients. This already works. Now i need to send data to Octave, mostly images and process them. To test this i wanted to receive and display a grayscale test image.

bufflen = 4096;
[data,count]=recv(b,bufflen);
imshow (data)

the image window opens but it is empty. The size of data is exactly the size of the image file i am sending. I also tried saving the image with

imwrite (data, "test.jpg");

this produced a file but every line of the image was in one long line. When i open the image with

imshow test.jpg

everything works as it should, the image window appears and shows the image.

I am sending the data via netcat with

>ncat.exe 127.0.0.1 12346 < test.jpg

this seems to work, i was able to transfer the image to another pc and view it there.

Every hint or tip is greatly appreciated, thank you.


回答1:


You are sending your jpeg as byte stream (ncat.exe 127.0.0.1 12346 < test.jpg) but you are trying to show is with imshow as it would be an uncompressed RGB, grayscale or index image. You can receive it and save it to a tempfile and then load it with imread. In this case graphics/image-magick will do the uncompression from JPE to RGB to you.




回答2:


Guessing here since you didn't provide much information, but it sounds like you're data is coming as a vector and you need to reshape it into an array for imshow

>> newdata = reshape(data, 64, 64)

You haven't shown us an example of the input data, so it is also possible that your data is a string of characters, while image arrays need to be numerical values. To verify before reshaping you could run:

>> class(data)

If so you will need to convert it to an array of numerical values. You can use str2num for that, but exactly how to do so will depend on what the string looks like, are there value separators, etc.

See:

https://www.gnu.org/software/octave/doc/interpreter/String-Conversions.html



来源:https://stackoverflow.com/questions/44029568/octave-display-image-received-by-socket-connection-doest-show

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!