element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • 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 & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • 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
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • 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
STEM Projects
  • Learn
  • Learning Center
  • STEM Academy
  • STEM Projects
  • More
  • Cancel
STEM Projects
Blog Virtual Eye System -- Post #5 -- Pi cam basics
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join STEM Projects to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: nikhil22
  • Date Created: 4 Sep 2015 7:57 AM Date Created
  • Views 544 views
  • Likes 2 likes
  • Comments 1 comment
  • teachers_pet
  • virtual_eye_system
  • matlab_raspberry_pi
  • pi_cam
  • teachers pet robotics design challenge
  • raspberrypi_education
Related
Recommended

Virtual Eye System -- Post #5 -- Pi cam basics

nikhil22
nikhil22
4 Sep 2015

Hi Folks!!

In the previous blog post, we have seen how to program the raspi and arduino to get the analog output of distance sensor converted to a physical distance value. As a continuation of our project let us get some insights in to how to work with Pi cam and lets start programming. There are many tutorials on the Pi cam, but as we are interfacing our Raspi using Matlab, this tutorial gives us an entirety about Pi Cam and the gist of that tutorial is given as follows.

 

Hardware description about Pi Cam:

 

Firstly connect the Pi cam's ribbon cable to the CSI interface jack on the Raspberry Pi in such a manner that the blue label is facing towards the Ethernet connection jack. The Pi cam accommodates an OmniVision's OV5647 5MP CMOS image sensor which has an image resolution of 2592 x 1944 Pixels and pixel size of 1.4 µm x 1.4 µm. It  accepts a Resolution  '160x120', '320x240', '640x480', '800x600', '1024x768', '1280x720', '1920x1080' and generally it has an image transfer rate of QSXGA(2592 x 1944)-15fps, 1080p-30fps, 960p- 45fps, 720p-60fps, VGA(640x480)-90fps and QVGA(320x240)-120fps. Below is the detailed description of the various formats and modes in Pi cam.

image

Programming Pi cam:

 

The Pi cam, after necessary connections, should be assigned an object using cameraboard function.

 

clear rpi % Clears variable rpi

rpi = raspi();                                       

cam = cameraboard(rpi, 'Resolution', '640 x 480'); %Creates an object to point to the Pi cam with given resolution

 

The above command sets the image transfer rate to 90 fps by default as it is VGA resolution. Now, to capture an image,

 

img = snapshot(cam);                                     % capture an image

imagesc(img);                                            %Image scale

drawnow;                                                 %Display it in a window

 

To view the properties of the Pi cam, just call the handle cam. And we can change these properties using the cam handle.

 

cam = cameraboard(rpi,'Resolution','1280x720')

cam =

 

 

Cameraboard with Properties:

 

 

                    Name: Camera Board  

              Resolution: '1280x720'       (View available resolutions)

                 Quality: 10              (1 to 100)

                Rotation: 0               (0, 90, 180 or 270)

          HorizontalFlip: 0             

            VerticalFlip: 0             

               FrameRate: 30              (2 to 30)

               Recording: 0             

 

 

   Picture Settings

              Brightness: 50              (0 to 100)

                Contrast: 0               (-100 to 100)

              Saturation: 0               (-100 to 100)

               Sharpness: 0               (-100 to 100)

 

 

   Exposure and AWB

            ExposureMode: 'auto'          (View available exposure modes)

    ExposureCompensation: 0               (-10 to 10)

                 AWBMode: 'auto'          (View available AWB modes)

            MeteringMode: 'average'       (View available metering modes)

 

 

   Effects

             ImageEffect: 'none'          (View available image effects)

      VideoStabilization: 'off'         

                     ROI: [0.00 0.00 1.00 1.00] (0.0 to 1.0 [top, left, width, height])

You can change the properties so easily with just one line of code......

 

cam.Rotation=180;                                % Rotates the image 180 degrees

% We can differentiate between Horizontal and vertical flip as follows:

cam.Horizontalflip = 'true';

% As seen in the above table of properties of Pi cam, we can just change any property using cam handle.

To record a video,

 

record(cam, 'vid.h264', 60);                   % Record a video named vid in h264 format for a peroid of 60 sec

getFile(rpi, 'vid.h264');                      % Copy the file from Raspi to host computer

 

%The raw H264 stream needs to be converted to a video file format, such as MP4, before you can play it in a media player or load it in MATLAB. Install FFmpeg software.

 

ffmpegDir = 'C:\ffmpeg-20140218-git-61d5970-win32-static';

cmd = ['"' fullfile(ffmpegDir, 'bin', 'ffmpeg.exe') '" -r 30 -i vid.h264 -vcodec copy myvid.mp4 &'];

[status, message] = system(cmd);

 

% Now you can view the video in matlab as follows:

 

vid = VideoReader('myvid.mp4')

for k = 1:vid.NumberOfFrames

    image(read(vid, k));

    drawnow;

end

 

The next blog post involves the integration of Pi cam and Servo mechanism (Pan and Tilt) for the detection and tracking of an object of interest. See you in the next blog post.

  • Sign in to reply

Top Comments

  • DAB
    DAB over 10 years ago +1
    Nice post. I have not had the time to dig into my Rpi camera, so it is very useful for me to see what lies hidden beneath to capabilities. Thanks DAB
  • DAB
    DAB over 10 years ago

    Nice post.

     

    I have not had the time to dig into my Rpi camera, so it is very useful for me to see what lies hidden beneath to capabilities.

     

    Thanks

    DAB

    • Cancel
    • Vote Up +1 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