# Sending frame from PYNQ z2 PS to FPGA

**URL:** <https://discuss.pynq.io/t/sending-frame-from-pynq-z2-ps-to-fpga/4098>\
**Category:** Support\
**Created:** [April 25, 2022, 6:27pm UTC](https://discuss.pynq.io/t/sending-frame-from-pynq-z2-ps-to-fpga/4098 "2022-04-25T18:27:20Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![dpk1](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/dpk1/32/3355_2.png) [@dpk1](https://discuss.pynq.io/u/dpk1)\
**Post date:** [April 25, 2022, 6:27pm UTC](https://discuss.pynq.io/t/sending-frame-from-pynq-z2-ps-to-fpga/4098/1 "2022-04-25T18:27:20Z")

</div>

I want to send video camera frame from Pynq-z2 Jupiter notebook to the FPGA PL side and vice-versa. So how do I create video IP in PL and process that in PS? Any kind of suggestion is welcomed.  
Thanks

---

<div class="post-metadata">

**Author:** ![marioruiz](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/marioruiz/32/2177_2.png) [@marioruiz](https://discuss.pynq.io/u/marioruiz)\
**Post date:** [April 26, 2022, 8:08am UTC](https://discuss.pynq.io/t/sending-frame-from-pynq-z2-ps-to-fpga/4098/2 "2022-04-26T08:08:35Z")

</div>

Hi @dpk1,

Did you check the composable overlay?

> [@The Composable Video Pipeline](https://discuss.pynq.io/t/the-composable-video-pipeline/2758):
>
> Hello PYNQ aficionados, Edit 10 March 2022: comments closed to request support open a new post in the [support category](https://discuss.pynq.io/c/support/30). I am pleased to announce that the PYNQ team has just released the composable (video) pipeline, this is an open source project and you can find it in GitHub [PYNQ\_Composable\_Pipeline](https://github.com/Xilinx/PYNQ_Composable_Pipeline) Note that through the blog, I will use the term “composable overlay” and “composable pipeline” interchangeably. What is a composable overlay? A composable overlay provides run time configuration…

Mario

---

<div class="post-metadata">

**Author:** ![jcollier](https://avatars.discourse-cdn.com/v4/letter/j/9dc877/32.png) [@jcollier](https://discuss.pynq.io/u/jcollier)\
**Post date:** [April 26, 2022, 11:16am UTC](https://discuss.pynq.io/t/sending-frame-from-pynq-z2-ps-to-fpga/4098/3 "2022-04-26T11:16:26Z")

</div>

Hello,  
Here is some code I put together using some references (noted in the code) that sends 800x600 frames from my USB webcam to the PL. On the PL side, it makes video frames from them and sends it out the HDMI output. This runs on my ZCU104.

```auto
# https://discuss.pynq.io/t/webcam-video-to-hdmi-output/3101
#https://discuss.pynq.io/t/how-to-stream-a-video-from-webcam-to-hdmi-out-using-only-base-overlay-of-pynq-z1/816

from pynq.overlays.base import BaseOverlay
from pynq.lib.video import *
import time
import cv2

base = BaseOverlay("base.bit")

#camera (input) configuration

frame_in_w = 800
frame_in_h = 600

# configure video output
Mode = VideoMode(frame_in_w,frame_in_h,24)
hdmi_out = base.video.hdmi_out
hdmi_out.configure(Mode,PIXEL_BGR)
hdmi_out.start()

# configure monitor (output) frame buffer size
frame_out_w = 1920
frame_out_h = 1080

# used to record the time when we processed last frame
prev_frame_time = 0
 
# used to record the time at which we processed current frame
new_frame_time = 0

# initialize camera from OpenCV

cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, frame_in_w);
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, frame_in_h);
print("Capture device is open: " + str(cap.isOpened()))

#Capture webcam video

while (True):
  ret, frame = cap.read()
  if ret:
     outframe = hdmi_out.newframe()
     outframe[:] = frame
     hdmi_out.writeframe(outframe)
     new_frame_time = time.time()
     fps = int(1/(new_frame_time-prev_frame_time))
     prev_frame_time = new_frame_time
     print("Frames per second : {0}". format(fps))
     
     
cap.release()
cv2.destroyAllWindows()

# print the camera fps settings 
cap.get(cv2.CAP_PROP_FPS)

```

Good luck,  
John

```auto

```

---

<div class="post-metadata">

**Author:** ![dpk1](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/dpk1/32/3355_2.png) [@dpk1](https://discuss.pynq.io/u/dpk1)\
**Post date:** [April 26, 2022, 5:10pm UTC](https://discuss.pynq.io/t/sending-frame-from-pynq-z2-ps-to-fpga/4098/4 "2022-04-26T17:10:13Z")

</div>

Is this only for HDMI\_in camera? This pynq.lib.video is a way to call the video IP which is build on PL into the PS? I want to send frame of any type of camera to the PL.  
Thanks

---

<div class="post-metadata">

**Author:** ![jcollier](https://avatars.discourse-cdn.com/v4/letter/j/9dc877/32.png) [@jcollier](https://discuss.pynq.io/u/jcollier)\
**Post date:** [April 26, 2022, 5:42pm UTC](https://discuss.pynq.io/t/sending-frame-from-pynq-z2-ps-to-fpga/4098/5 "2022-04-26T17:42:23Z")

</div>

That code is using the OpenCV capture device (i.e. a USB webcam), not HDMI-IN.

This code would copy HDMI-IN to HDMI-OUT (without using the PS)

```auto
#https://stackoverflow.com/questions/59578954/pynq-z1-how-to-stream-a-video-from-hdmi-input-to-hdmi-output-using-base-overla

from pynq.overlays.base import BaseOverlay
from pynq.lib.video import *
import time

base = BaseOverlay("base.bit")

hdmi_in = base.video.hdmi_in
hdmi_out = base.video.hdmi_out
hdmi_in.configure()
hdmi_out.configure(hdmi_in.mode)
hdmi_in.start()

     
while True:
    try:
        frame = hdmi_in.readframe()
        hdmi_out.writeframe(frame)
        time.sleep(0.016)
    except KeyboardInterrupt:
        break

hdmi_in.close()
hdmi_out.close()

```

---

<div class="post-metadata">

**Author:** ![dpk1](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/dpk1/32/3355_2.png) [@dpk1](https://discuss.pynq.io/u/dpk1)\
**Post date:** [April 27, 2022, 4:43am UTC](https://discuss.pynq.io/t/sending-frame-from-pynq-z2-ps-to-fpga/4098/6 "2022-04-27T04:43:53Z")

</div>

Thank you for your response. Just to confirm,  
This "from pynq.lib.video import \* " library is used to transfer frames between PS and PL?  
Also Video Pipeline IP is built in PL side. By using pynq.lib, we are accessing that IP using PS jupiter notebook. Is it so?  
Is this method work for all types of cameras like USB monocular, pyrealsense etc.?  
Thanks

---

<div class="post-metadata">

**Author:** ![dpk1](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/dpk1/32/3355_2.png) [@dpk1](https://discuss.pynq.io/u/dpk1)\
**Post date:** [April 30, 2022, 10:31am UTC](https://discuss.pynq.io/t/sending-frame-from-pynq-z2-ps-to-fpga/4098/7 "2022-04-30T10:31:26Z")

</div>

Any support on how to create IP for Video camera in VIVADO and use of that IP in PS using jupiter notebook?  
Thanks

---

<div class="post-metadata">

**Author:** ![dpk1](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/dpk1/32/3355_2.png) [@dpk1](https://discuss.pynq.io/u/dpk1)\
**Post date:** [May 2, 2022, 5:32pm UTC](https://discuss.pynq.io/t/sending-frame-from-pynq-z2-ps-to-fpga/4098/8 "2022-05-02T17:32:00Z")

</div>

Hii, I am having issue while installing composible overlay package. When I am doing  
“pip install PYNQ\_Composable\_Pipeline/” , pynq-2.7.0.tar.gz is installing and it is giving me error “ERROR: Package ‘pynq-composable’ requires a different Python: 3.6.5 not in ‘\>=3.8.0’”. I am using pynq-z2 and image pynq\_z2\_v2.6.0. Any solution how can I install it in my board?

---

<div class="post-metadata">

**Author:** ![marioruiz](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/marioruiz/32/2177_2.png) [@marioruiz](https://discuss.pynq.io/u/marioruiz)\
**Post date:** [May 3, 2022, 6:51am UTC](https://discuss.pynq.io/t/sending-frame-from-pynq-z2-ps-to-fpga/4098/9 "2022-05-03T06:51:39Z")

</div>

Hi @dpk1,

The latest version of the composable overlay depends on PYNQ 2.7. You will need to burn an SD card with PYNQ 2.7.

Mario

---

<div class="post-metadata">

**Author:** ![dpk1](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/dpk1/32/3355_2.png) [@dpk1](https://discuss.pynq.io/u/dpk1)\
**Post date:** [May 5, 2022, 4:27am UTC](https://discuss.pynq.io/t/sending-frame-from-pynq-z2-ps-to-fpga/4098/10 "2022-05-05T04:27:32Z")

</div>

Thanks, pynq 2.7 worked.  
I want to confirm one thing, Is this composable overlay using OpenCV for accessing video frames or video IP is built on PL and we are accessing that IP in PS?

---

<div class="post-metadata">

**Author:** ![marioruiz](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/marioruiz/32/2177_2.png) [@marioruiz](https://discuss.pynq.io/u/marioruiz)\
**Post date:** [May 5, 2022, 6:51am UTC](https://discuss.pynq.io/t/sending-frame-from-pynq-z2-ps-to-fpga/4098/11 "2022-05-05T06:51:03Z")

</div>

Hi,

OpenCV is only used to capture frames from a webcam or file in the PS. Then quickly moved to PynqBuffer.  
All of the vision function implemented on hardware are accelerated hardware version of their corresponding OpenCV counterpart.

Mario

---

<div class="post-metadata">

**Author:** ![dpk1](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/dpk1/32/3355_2.png) [@dpk1](https://discuss.pynq.io/u/dpk1)\
**Post date:** [May 5, 2022, 6:56am UTC](https://discuss.pynq.io/t/sending-frame-from-pynq-z2-ps-to-fpga/4098/12 "2022-05-05T06:56:45Z")

</div>

Thanks,

> Where can I find hardware-accelerated IP so that I can modify or take references for my work?  
> Also, I want to send a video frame from a USB camera. Will this composable pipeline would work for USB type camera?

---

<div class="post-metadata">

**Author:** ![marioruiz](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/marioruiz/32/2177_2.png) [@marioruiz](https://discuss.pynq.io/u/marioruiz)\
**Post date:** [May 5, 2022, 7:46am UTC](https://discuss.pynq.io/t/sending-frame-from-pynq-z2-ps-to-fpga/4098/13 "2022-05-05T07:46:39Z")

</div>

Between the documentation page an the repo your question should be answer.  
The vision IP come from the Vitis accelerated libraries.

Mario
