Camera module 3 connect to raspberry pi using node red to generate a dashboard for streaming purpose

Hi guys, I currently doing a project related to camera module 3, raspberry pi 3 and node red. The coding part i already done and can run in thonny. But when it comes to node red, i am blank because i don't know where to start from. According to my senior's flow, this is what he use to generate the dashboard but he didn't specifies the settings in the node. Need help from u guys.

Welcome to the forum @Chow0605

Start by watching this playlist: Node-RED Essentials. The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

I have done watching the videos but i still could not understand what i have done wrong in my flow.....

What node is being used to get data from the camera? If you don't know what node has been installed then look in the dropdown menu Manage Pallet to see what nodes have been installed.

Hi guys, is it possible for me to insert this coding into the python shell in node red can get the whole system running and display the offset data in dashboard?
the coding is as below:

<from picamera2 import Picamera2 
from libcamera import controls 
import cv2 
import numpy as np 
import time 
import csv 

picam2 = Picamera2() 
config = picam2.create_preview_configuration() 
picam2.configure(config) 
picam2.set_controls({"AfMode":controls.AfModeEnum.Continuous}) 
picam2.start() 

regulated_line_position = None 
pixel_to_mm_ratio = 0.027 
start_time = time.time() 
interval = 1  

csv_filename = "offset_data.csv" 
with open(csv_filename, mode='w', newline='') as csv_file: 
    fieldnames = ['Timestamp', 'Distance_mm']  
    writer = csv.DictWriter(csv_file, fieldnames=fieldnames) 
    writer.writeheader() 

while True: 
    with open(csv_filename, mode='a', newline='') as csv_file: 
        writer = csv.DictWriter(csv_file, fieldnames=fieldnames) 
        
        im = picam2.capture_array() 
        gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY) 
        edges = cv2.Canny(gray, 50, 150) 

        roi_y = 220 
        roi_height = im.shape[0] // 16 
        roi = edges[roi_y:roi_y + roi_height, :] 
        lines = cv2.HoughLinesP(roi, 1, np.pi / 180, threshold=100, minLineLength=100, maxLineGap=10)
        
        if lines is not None: 
            min_distance = float('inf') 
            for line in lines: 
                x1, y1, x2, y2 = line[0] 
                angle = np.arctan2(y2 - y1, x2 - x1) * 180 / np.pi 

                if 175 <= angle <= 185 or -5 <= angle <= 5 or 176 <= angle <= 186 or -6 <= angle <= 6: 
                    line_center = y2  
                    image_center = im.shape[1] / 2 
                    offset_pixels = line_center - image_center 
                    distance_mm = abs(offset_pixels) * pixel_to_mm_ratio 

                    if distance_mm < min_distance: 
                        min_distance = distance_mm 

                        cv2.rectangle(im, (x1, roi_y + y1), (x2, roi_y + y2), (0, 255, 0), 2) 

            if min_distance != float('inf') and time.time() - start_time >= interval: 
                timestamp = time.strftime('%Y-%m-%d %H:%M:%S') 
                writer.writerow({'Timestamp': timestamp, 'Distance_mm': min_distance}) 
                print("Distance to regulated line (mm):", min_distance) 
                start_time = time.time() 

        cv2.line(im, (0, im.shape[0] // 2), (im.shape[1], im.shape[0] // 2), (255, 0, 0), 1) 

        cv2.imshow("Frame", im) 

        if cv2.waitKey(1) & 0xFF == ord('q'): 
            break 

picam2.release() 
cv2.destroyAllWindows()

the flow in node red is as below:

this should be working according to my collage senior, but i could not get in working, soon as i deploy it, it shows a few lines under the python shell and immediately change to script closed and stop.

Seeing that this is a continuation of a thread you opened yesterday, I have moved your post to this thread.

inject node to inject the whole system, python shell to run the coding, a chart and a gauge to display the data