Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
np array tolist and back
#1
Hi everyone,

I am pretty new to Python and I am seeking some help and guidance.

I use OpenCV to grab frames from video cap:

ret, frame = self.cap.read()
frame.shape here is (480,640,3)

For subsequent processing, I need to serialize the value in order to pass it on to remote consumers:

data = np.fromstring(frame, np.uint8)
message = data.tolist()
On the other end, I am trying to reverse that:

frame = np.array(incoming_message, dtype=np.uint8)
cv2.imwrite('debug.jpg', frame)
but clearly, it is not the right way to do it.
How should I proceed to obtain the original nparray so that I can save it as an image?

Please, advise.

Thanks in advance!
Cheers,
G
Reply
#2
maybe numpy.reshape
https://numpy.org/doc/1.18/reference/gen...shape.html
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Man! you are saving me so much time! :)

Thanks so much!!

...

frame = np.array(incoming_message, dtype=np.uint8)
reshaped_frame = frame.reshape((480, 640, 3))
cv2.imwrite('debug.jpg', reshaped_frame)
...

Cheers,
G.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  variable call back into an array yamifm0f 3 2,379 Jun-07-2019, 02:44 PM
Last Post: heiner55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020