Connecting raspberry pi 4 camera with python to Labview Dashboard

Hi! I’m from team 1860 AlphaBots.
We are trying to connect a raspberry pi 4 (which is going to do all image processing) with the roborio. We are programming the pi 4 with python and the roborio with labview. We would like to send the video stream from the pi to the LabView Dashboard, but couldn’t make it work. The pi is running the FRCVision Raspbian image. We are using the following code in the raspberry pi:

from cscore import CameraServer
from networktables import NetworkTables
from enum import Enum
import cv2
import numpy as np
import math
import json
import logging


netTable = NetworkTables.getTable("SmartDashboard")

processImage = GripPipeline()
def main():
    distanceParameters = getDistanceParameters()

    cs = CameraServer.getInstance()
    camera = cs.startAutomaticCapture()
    camera.setResolution(320, 240)
    cvSink = cs.getVideo()
    outputStreamEdited = cs.putVideo("processedImage", 320, 240)
    outputStreamBinary = cs.putVideo("binaryImage", 320, 240)
    img = np.zeros(shape=(240, 320, 3), dtype=np.uint8)
    while True:
        t, img = cvSink.grabFrame(img)
        if t == 0:
        processedImage, binaryImage, imageHeight = processImage.process(img)
        distance = findDistance(imageHeight, distanceParameters)
        netTable.putNumber("Distance", 1860)


We were hoping that this would make two video streams available on the dashboard and publish a variable “Distance” = 1860 on the networktable.

Is the code on the pi right? Where should we look to learn more about these connections?

You need to configure NetworkTables to start a client to connect to the robot by passing server='roborio-TEAM-frc.local' to the initialize call. Also see the FRCVision example Python program for an example of this.


This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.