from SinglePic import run_inference
import cv2
import numpy as np
def decodeVid(vidFile):
video_capture = cv2.VideoCapture(vidFile)
steering_angle2 = 40 # Initial steering angle for the second line
steering_angle1 = 135 # Initial steering angle for the first line
newVd = True
height, width = 0,0
center_x1, center_y1 = 0, 0
center_x2, center_y2 = 0, 0
x1, y1 = 0, 0
x2, y2 = 0, 0
pt = True
while video_capture.isOpened():
ret, frame = video_capture.read()
if not ret:
break
processed_frame,driveAbleArea,steerin = run_inference(frame)
# Adding lines
if newVd:
height, width = processed_frame.shape[:2]
center_x2 = 400
center_y2 = 220
center_x1 = 300
center_y1 = 220
newVd = False
# Define the length of the lines
line_length = min(height, width) // 2
# Create a copy of the frame to draw lines on
frame_with_lines = processed_frame.copy()
# Calculate the endpoints of the lines based on the steering angles and positions
angle_radians2 = np.deg2rad(steering_angle2)
x2 = int(center_x2 + line_length * np.cos(angle_radians2))
y2 = int(center_y2 + line_length * np.sin(angle_radians2))
angle_radians1 = np.deg2rad(steering_angle1)
x1 = int(center_x1 + line_length * np.cos(angle_radians1))
y1 = int(center_y1 + line_length * np.sin(angle_radians1))
cv2.line(frame_with_lines, (center_x2, center_y2), (x2, y2), (255,0,0), thickness=2)
cv2.line(frame_with_lines, (center_x1, center_y1), (x1, y1), (255,0,0), thickness=2)
rgb_image = cv2.cvtColor(frame_with_lines,cv2.COLOR_BGR2RGB)
steering_angle2 += steerin[0]
steering_angle1 += steerin[1]
'''
for finding cordinates
if pt:
for i, cor in enumerate(line1_px):
if i%150 == 0:
print(cor)
pt = False
'''
# Display the processed frame with lines
cv2.imshow('Processed Frame', rgb_image)
# Adjust dynamically
key = cv2.waitKey(1) & 0xFF
if key == ord('q'):
break
elif key == ord('p'):
print(f"x1 = {x1}\ny1 = {y1}\nx2 = {x2}\ny2 = {y2}")
# Release the video capture
video_capture.release()
# Close all OpenCV windows
cv2.destroyAllWindows()
def main():
decodeVid('dataset\gtaTest.mp4')
if __name__ == "__main__":
main()
Comments