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
logging.basicConfig(level=logging.DEBUG)
NetworkTables.initialize()
netTable = NetworkTables.getTable("SmartDashboard")
processImage = GripPipeline()
def main():
distanceParameters = getDistanceParameters()
cs = CameraServer.getInstance()
cs.enableLogging()
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:
processImage.getParameters()
t, img = cvSink.grabFrame(img)
if t == 0:
outputStreamEdited.notifyError(cvSink.getError());
continue
processedImage, binaryImage, imageHeight = processImage.process(img)
distance = findDistance(imageHeight, distanceParameters)
netTable.putNumber("Distance", 1860)
outputStreamEdited.putFrame(processedImage)
outputStreamBinary.putFrame(binaryImage)
main()
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?