project help

I designed an automatic car that could follow the black traces on the white ground. The Raspberry Pi board is the brain of this system. And the Picamera, which is attached to the Raspberry Pi, can be considered as the eyes of the car. It faces the ground and collects images/video data in real-time. Then the Raspberry Pi board decides to turn right, turn left, or keep going straight by analyzing the obtained image data. After that, the Raspberry Pi sends its decision to the Arduino board via SPI protocol. Arduino converts the received steering information into the voltage value applied to the L298n motor.
here is the code I have for the Arduino, I need help writing the python code for raspberry pi using the SPI protocol to connect the two.

int rightforward =10;
int leftforward = 9;
int const ENA = 6;
int const ENB = 5;
int leftreverse = 8;
int rightreverse = 11;


 
void setup() {

 //setup output pin
 pinMode(leftreverse, OUTPUT);
 pinMode(rightreverse, OUTPUT);
 pinMode(rightforward, OUTPUT);
 pinMode(leftforward, OUTPUT);
 pinMode(ENA, OUTPUT);
 pinMode(ENB, OUTPUT);

 //forward direction
 digitalWrite(leftreverse, LOW);
 digitalWrite(rightforward, LOW);
 digitalWrite(leftforward, HIGH);
 digitalWrite(rightforward, HIGH);

}



  
 
}
void loop() {
 // put your main code here, to run repeatedly:
//turning right
  digitalWrite(leftforward,HIGH);
  digitalWrite(rightforward, LOW);
  digitalWrite(ENA, HIGH);
  digitalWrite(ENB, HIGH);
 }
//turning left
  digitalWrite(leftforward, LOW);
  digitalWrite(rightforward, HIGH);
  digitalWrite(ENA, HIGH);
  digitalWrite(ENB, HIGH);
   
 }
//going straight
 digitalWrite(leftreverse, LOW);
 digitalWrite(rightforward, LOW);
 digitalWrite(leftforward, HIGH);
 digitalWrite(rightforward, HIGH);
 digitalWrite(ENA, HIGH);
 digitalWrite(ENB, HIGH);
 }
 }
}

here is the code I have for the raspberry pi,
import time
import numpy as np
import cv2
import smbus2 as smbus
from picamera import PiCamera

ard = 0x8 //arduino address
bus = smbus.SMBus(1)

with PiCamera() as src:

src.resolution =(640,480)
src.framerate = 30
src.shutter_speed = 75000
output = np.empty((480,640, 3), dtype=np.uint8)
while(True):
start_time = time.time()
src.capture(output, format='bgr', use_video_port=True)

gray = cv2.cvtColor(output, cv2.COLOR_BGR2GRAY)

gray[gray < 50] =0
gray[gray > 50] = 255
direction=''


top_center = np.average(np.where(gray[0] ==0 ))
bottom_center = np.average(np.where(gray[-1] ==0))

if top_center - bottom_center > 25:
print("Turn right")
direction = '1'

elif top_center - bottom_center <-25:
print("Turn left")
direction = '2'

else:
print("Stay")
direction = '3'

cv2.imshow('Output', gray)
key = cv2.waitKey(1)&0xFF
if key==ord("q"):
break

For python-code you will get much better help in a python-forum. The Arduino-IDE is designed for coding in C++.
best regards Stefan

If you want to use SPI, I would recommend to check this guide. In my opinion, this will do.