element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Experimenting with Extreme Environments
  • Challenges & Projects
  • Design Challenges
  • Experimenting with Extreme Environments
  • More
  • Cancel
Experimenting with Extreme Environments
Blog CycleSafe - #3 - The Preparations for the Road Test and the Data Collection
  • Blog
  • Forum
  • Documents
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Experimenting with Extreme Environments to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: vlasov01
  • Date Created: 2 Jun 2024 1:01 PM Date Created
  • Views 360 views
  • Likes 8 likes
  • Comments 2 comments
  • python
  • opencv
  • compute module 4
  • Hammond 1554VA2GYCL
  • video recording
  • Experimenting with Extreme Environments
Related
Recommended

CycleSafe - #3 - The Preparations for the Road Test and the Data Collection

vlasov01
vlasov01
2 Jun 2024

Design Changes

When I tried to connect the RPi Compute Module 4 I/O board with RPi Camera v2 I realized that they were not compatible. So, As I have a USB camera I've decided to reuse it instead of purchasing an additional camera. Here is the new design diagram.

image

Need for Data and Test Preparation

I need to collect video recordings, so I can use them to test the application and its car (obstacles) detection processing. So I need to complete a bike ride with the prototype. I've decided to use a power bank which has a 12V output as the power source. The battery can support RPi for more than a day. And it fits well inside the enclosure.

components and enclosure

I've added some packing materials to isolate components inside the enclosure and closed it.

the enclosure closed

I've purchased a Large-Capacity Rear Seat Bag for Outdoor Cycling and a Bicycle Rear Seat Carrier - Luggage Cargo Rack to host my HAMMOND 1554VA2GYCL Plastic Enclosure and other components. Once the order was delivered I installed the rack and the bag on my bicycle and put the prototype inside the bag.

{gallery}Bicycle with a rack

rack back view

The rack back view

The rack top view

The rack-top view

Inside the bag

Inside the bag

Video Recorder App

I wrote a Python app using the OpenCV library to record 20 minutes of video. Then I configured it to be started immediately after the RPi boot.

import cv2
import datetime

def get_current_datetime_string():
    """
    Returns the current date and time as a string in the format "YYYYMMDDHHMMSS".
    """
    now = datetime.datetime.now()
    return now.strftime("%Y%m%d%H%M%S")

# function video capture
cap = cv2.VideoCapture("/dev/video0",  cv2.CAP_V4L2)

if not cap.isOpened():
    print("Error: Could not open video Source.")
    exit()
"""
uvcdynctrl -f
Ubisoft camera
Pixel format: YUYV (YUYV 4:2:2; MIME type: video/x-raw-yuv)
  Frame size: 640x480
    Frame rates: 30, 20, 15, 10, 5, 1
  Frame size: 320x240
    Frame intervals: 1/30, 1/20, 1/15, 1/10, 1589/15625, 1/1
  Frame size: 160x120
    Frame intervals: 1/30, 1/20, 1/15, 1/10, 1589/15625, 1/1
  Frame size: 176x144
    Frame intervals: 1/30, 1/20, 1/15, 1/10, 1589/15625, 1/1
  Frame size: 352x288
    Frame intervals: 1/30, 1/20, 1/15, 1/10, 1589/15625, 1/1

DYNEX camera
Pixel format: MJPG (Motion-JPEG; MIME type: image/jpeg)
  Frame size: 640x480
    Frame rates: 30, 25, 20, 15, 10, 5
  Frame size: 352x288
    Frame rates: 30, 25, 20, 15, 10, 5
  Frame size: 320x240
    Frame rates: 30, 25, 20, 15, 10, 5
  Frame size: 176x144
    Frame rates: 30, 25, 20, 15, 10, 5
  Frame size: 160x120
    Frame rates: 30, 25, 20, 15, 10, 5
  Frame size: 1280x1024
    Frame rates: 15, 10, 5

"""
cap.set(3,320)
cap.set(4,320)

# rame rate or frames per second
fps = 30
 
# Width and height of the frames in the video stream

size = (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)), int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))
#size = (320, 320)
"""
Create a VideoWriter object. 
FourCC FourCC is a 4-byte code used to specify the video codec. The list of available codes can be found in fourcc.org. It is platform dependent.
number of frames per second (fps)
frame size should be passed.
May specify isColor flag. If it is True, encoder expect color frame, otherwise it works with grayscale frame.
"""
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
videoWriter = cv2.VideoWriter('/var/lib/tail/tail-'+get_current_datetime_string()+'.mp4', 
    fourcc, fps, size)
    #cv2.VideoWriter_fourcc('I','4','2','0'), fps, size)
 
success, frame = cap.read()
 
# 20 minutes maximum recording
numFramesRemaining = 20*60*fps
 
# loop until there are no more frames and variable > 0
while success and numFramesRemaining > 0:
    videoWriter.write(frame)
    success, frame = cap.read()
    if not success:
        print("Failed to grab the frame from the video source, Trying again...")
    #else:
    #    print(f'Height: {frame.shape[0]}, Width: {frame.shape[1]}')

    # cv2.imshow('frame',frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
    numFramesRemaining -= 1
 
#Closes video file or capturing device
cap.release()
videoWriter.release()
cv2.destroyAllWindows()

Ready to test

At this point, I was ready to record the video and start further development.

  • Sign in to reply
  • DAB
    DAB over 1 year ago

    You are making good progress.

    Testing should be lots of fun.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • genebren
    genebren over 1 year ago

    Looking good! Keep up the good work.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube