davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

step by step Pi Cam tutorial and C/C++ programming guide

Tue Apr 12, 2016 4:45 pm

hey,
where can I find a step by step Pi Cam tutorial, or a book, feat. an overview and programming guides about
- the cam specs, install the drvers and the c/C++ libs
- showing several projects what one can do with the cam, programming in C, e.g., demonstrating one or the other example about:
color BLOB detection,
shape recognition (e.g., a "X" or a "O" or a "+" or a "|"),
detecting moving objects,
face detection and recognition,
follow a line on the ground with a mobile robot (differential steering),
follow a colored BLOB (e.g., a green ball or a purple dinosaur) mounted on a 3D turret,
follow a specific shape (e.g., a "X" or a "O") with a mobile robot
follow a recognized face...
a.s.o.
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: step by step Pi Cam tutorial and C/C++ programming guide

Tue Apr 12, 2016 5:51 pm

any helpful hints about good recommendable guides and tutorials?
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

texy
Forum Moderator
Forum Moderator
Posts: 5161
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: step by step Pi Cam tutorial and C/C++ programming guide

Tue Apr 12, 2016 6:11 pm

I've deleted some unnecessarily posts from this thread - play nice, or not at all.
Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: step by step Pi Cam tutorial and C/C++ programming guide

Tue Apr 12, 2016 8:46 pm

hi, if you follow these instructions you'll have your camera running in no time with either bash or python.

If you read this book you will be on your way to programming your projects on the Raspberry PI with gusto!

:ugeek:
marcus
:ugeek:

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: step by step Pi Cam tutorial and C/C++ programming guide

Tue Apr 12, 2016 9:04 pm

PS... the book link referenced :roll: above (on Amazon) will point you also to other excellent materials related to programming the Raspberry PI.

Best of luck.
marcus
:ugeek:

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: step by step Pi Cam tutorial and C/C++ programming guide

Wed Apr 13, 2016 7:18 am

thank you,
at your first link they say "Once you’re connected, test the camera and try using it with Bash or Python."
The links which they are providing there are also only about that, but I don't see anything about C/C++ API libraries and programming.

But I don't use bash or Python, I need C/C++ libs.

Also the 2nd link says: "Programming the Raspberry Pi, Second Edition: Getting Started with Python"

I don't ever use Python, I just use C/C++ in the Geany IDE, and for that purpose I need a Pi Cam tutorial, guide, or book.
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: step by step Pi Cam tutorial and C/C++ programming guide

Wed Apr 13, 2016 7:39 am

davenull wrote: I don't ever use Python, I just use C/C++ in the Geany IDE, and for that purpose I need a Pi Cam tutorial, guide, or book.
Try these three links (all found on google) which address your issue:

My Robot Blog

How to Control Camera from C++

Best way to Access Camera from C

PS There are lots of others too...

:ugeek:
marcus
:ugeek:

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: step by step Pi Cam tutorial and C/C++ programming guide

Wed Apr 13, 2016 7:53 am

thank you very much, I quickly checked the links and they provide already a lot of basic information.

Nevertheless, I see just "basic low level functions" for the very first start to install the drivers and the C/C++ libs, to get an image or to make it possible to access openCV, e.g.,

Code: Select all

//create 4 textures of decreasing size
        //pick a level to read based on current frame (flicking through them every 30 frames)
        //lock the chosen buffer, and copy it directly into the corresponding texture
                //if doing argb conversion just copy data directly
                //if not converting argb the data will be the wrong size so copy it in
                //via a temporary buffer just so we can observe something happening!
        //begin frame, draw the texture then end frame (the bit of maths just fits the image to the screen while maintaining aspect ratio)

Code: Select all

 int main ( int argc,char **argv ) {
    raspicam::RaspiCam_Cv Camera;
    cv::Mat image;
    //set camera params
    //Open camera
    //Start capture
    cout<<"Capturing "<<nCount<<" frames ...."<<endl;
    for ( int i=0; i<nCount; i++ ) {
        Camera.grab();
        Camera.retrieve ( image);
        if ( i%5==0 )  cout<<"\r captured "<<i<<" images"<<std::flush;
    }
    //show time statistics
      cout<< secondsElapsed<<" seconds for "<< nCount<<"  frames : FPS = "<<  ( float ) ( ( float ) ( nCount ) /secondsElapsed ) <<endl;
    //save image 
    cv::imwrite("raspicam_cv_image.jpg",image);
    cout<<"Image saved at raspicam_cv_image.jpg"<<endl;
}
but there are no practical applications like I described above in my TO post.
- showing several projects what one can do with the cam, programming in C, e.g., demonstrating one or the other example about:
color BLOB detection (edit: e.g. sort recognized BLOBS by color, size, and location),
shape recognition (e.g., a "X" or a "O" or a "+" or a "|"),
detecting moving objects,
face detection and recognition,
follow a line on the ground with a mobile robot (differential steering),
follow a colored BLOB (e.g., a green ball or a purple dinosaur) mounted on a 3D turret,
follow a specific shape (e.g., a "X" or a "O") with a mobile robot
follow a recognized face...
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

User avatar
jbeale
Posts: 3675
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: step by step Pi Cam tutorial and C/C++ programming guide

Wed Apr 13, 2016 3:44 pm

I believe the most common approach to the specific machine vision applications you mention (color blobs, etc.) is to use the OpenCV library http://opencv.org/. There is a fair amount written about OpenCV, it is not specific to Raspberry Pi. You could write your own code to duplicate what OpenCV does, but I'm not sure why you'd want to.
OpenCV is released under a BSD license and hence it’s free for both academic and commercial use. It has C++, C, Python and Java interfaces and supports Windows, Linux, Mac OS, iOS and Android. OpenCV was designed for computational efficiency and with a strong focus on real-time applications. Written in optimized C/C++, the library can take advantage of multi-core processing. Enabled with OpenCL, it can take advantage of the hardware acceleration of the underlying heterogeneous compute platform. Adopted all around the world, OpenCV has more than 47 thousand people of user community and estimated number of downloads exceeding 9 million. Usage ranges from interactive art, to mines inspection, stitching maps on the web or through advanced robotics. --from http://opencv.org/

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: step by step Pi Cam tutorial and C/C++ programming guide

Wed Apr 13, 2016 3:50 pm

hmmm... thank you, but that actually knocks me out.
I would need some practical examples , using the cam with opencv then, where I can start with, to do some kind of things like these ones, providing the source code, and a tutorial how it works, and several more things, step by step:

https://www.youtube.com/watch?v=ken1zjEb3OM

https://www.youtube.com/watch?v=9Rk8K6oQ-xQ
Last edited by davenull on Wed Apr 13, 2016 5:16 pm, edited 1 time in total.
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

User avatar
jbeale
Posts: 3675
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: step by step Pi Cam tutorial and C/C++ programming guide

Wed Apr 13, 2016 5:13 pm

Here's a C++ example using OpenCV to detect colors, maybe it helps you get started.
http://opencv-srf.blogspot.com/2010/09/ ... ation.html

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: step by step Pi Cam tutorial and C/C++ programming guide

Wed Apr 13, 2016 5:25 pm

hmmm, but that seems to be extremely complicated stuff...

what I would need would be a simple but powerful high-level API, something like this one, detecting colored blobs and sending them to the calling function for further processing:

http://cmucam.org/projects/cmucam5/wiki ... Arduino%29

http://cmucam.org/projects/cmucam5

http://cmucam.org/attachments/download/ ... -0.1.7.zip

Code: Select all

#include <SPI.h>  
#include <Pixy.h>

// This is the main Pixy object 
Pixy pixy;

void setup()
{
  Serial.begin(9600);
  Serial.print("Starting...\n");

  pixy.init();
}

void loop()
{ 
  static int i = 0;
  int j;
  uint16_t blocks;
  char buf[32]; 
  
  // grab blocks!
  blocks = pixy.getBlocks();
  
  // If there are detect blocks, print them!
  if (blocks)
  {
    i++;
    
    // do this (print) every 50 frames because printing every
    // frame would bog down the Arduino
    if (i%50==0)
    {
      sprintf(buf, "Detected %d:\n", blocks);
      Serial.print(buf);
      for (j=0; j<blocks; j++)
      {
        sprintf(buf, "  block %d: ", j);
        Serial.print(buf); 
        pixy.blocks[j].print();
      }
    }
  }  
}
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: step by step Pi Cam tutorial and C/C++ programming guide

Thu Apr 14, 2016 4:45 pm

looks as if there is no whole-in-one tutorial or book / guide available, suitable for newbies... :-/
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

Return to “Camera board”