Ask Your Question
0

How to use imshow when png is loaded in memory

asked 2019-05-17 11:13:13 -0500

Saul R gravatar image

My program receives PNG buffers from TCP connection. I have an unsigned character pointer to the PNG file. I want to show the PNG image with imshow as they are received (i.e. sort of a video stream of PNG images).

So far I am not able to achieve this since imshow wants a cv::mat and I don't know how to convert from uchar * (png raw file data) to cv::mat.

Thank you.

edit retag flag offensive close merge delete

Comments

1

You have to wrap the raw data into a Mat first. Maybe is better if you compile OpenCV with FFMPEG enabled so you can "directly" handle TCP connection as far as I know. By the way, VideoCapture class also let you get video stream from an IP, maybe you can try to feed that class directly with your TCP socket.

I never faced this situation, to be honest when I have to deal with real time streming I prefere to use ROS.

Edit: @berak gave to you the simplest way to solve it :-)

HYPEREGO gravatar imageHYPEREGO ( 2019-05-17 11:23:15 -0500 )edit
1

Also checkout the answer here https://stackoverflow.com/questions/2...

SCodeZ gravatar imageSCodeZ ( 2019-05-17 11:55:29 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2019-05-17 11:18:19 -0500

berak gravatar image

you can use imdecode , like:

vector<uchar> tcp_data = ...;
Mat img = imdecode(tcp_data, IMREAD_UNCHANGED);
edit flag offensive delete link more

Comments

Thanks guys!!! trying answer right now....

Saul R gravatar imageSaul R ( 2019-05-17 11:53:37 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-05-17 11:13:13 -0500

Seen: 38 times

Last updated: May 17