It's possible to get a capture from CMOS camera ?

Mentor
Hi all !

I want to get a capture from CMOS camera. I tried using V4l but ioctl
function drop an error. Also I tried with OpenCV and I have the same error.

I tried with usb webcam but after plug in I can't find /dev/vide0.

Why my kernel 2.6.29 doesn't have /dev/video0 ?

How can I get a capture from CMOS camera or using USB Webcam ?

Many Thanks !

Mentor

Vladimir Fonov
Hello,

the CAM130 driver doesn't conform to V4L specification unfortunately. So,
the device name is /dev/camera and to capture the image you just have to
open this device and read 614400 bytes from it - it will capture a frame in
RGB565 format. 

I have started modifying the driver to make it more useful, result of my
efforts is here:  http://code.google.com/p/s3c2440camera . But if you want
to use it, you will have to replace the kernel. 

The USB camera should work if you have UVC device or something supported by
GSPCA driver, then it will appear as /dev/video0. If your camera is not
detected then it's not supported by this kernel.

Mentor
Hi Vladimir !

Thanks so much for you assistance with my problem. I have some questions if
you have time for me. I want to use the camera for real time image
processing (interfacing with OpenCV or V4L). After a long time on google
search I decide to implement this using one of two methods:

1. To get a frame from CMOS camera in RGB565 format ( exactly like you said
) and convert it into OpenCV buffer ( "Ipl format" ). And here I need your
help. It's this possible ?

2. To buy a USB camera (UVC device) and try to interfacing it with OpenCV.
Can I use V4L or OpenCV in this case ? Please, give me a model camera that
is supported by mini2440.

3. I can use your modified driver but can I interfacing it with V4L or
OpenCV ?

Which method you think it is fastest ?

Any other method you have I'm ready to try it.

You are a really helpful man and I'm waiting for your advice.

Thanks so much,
      Mentor

Vladimir Fonov
Hello,

1. that would work, using it is pretty straightforward

2. I suppose you can use OpenCV to read from device in this case, but take
note that USB interface on FriendlyARM is FullSpeed (i.e not HiSpeed), so
some uvc cameras refuse to work with full resolution or produce only mjpeg
compressed frames. I have a Dynex 1.3 Mpix webcam from BestBuy - it refuses
to capture uncompressed frames on mini (works fine on desktop) and a
Logitech Quickcam Pro 9000 - it only captures  176x144 uncompressed frames 
on mini. 

3. I didn't try it with OpenCV, it is still a work in progress. The driver
I made supports reading (no memory mapping) and capturing in YUV422P
format. You can get 640x480 @ 30 fps with it .

ASUStudent
Vladimir,  We are trying to use your driver and were wondering whether it
is possible to save the images captured to a directory on the mini2440
itself instead of streaming them?

Vladimir Fonov
Hello,

yes, it is possible. Actuall, included together with the drivers source
there is a simple application which captures N frames and saves them as a
series of TIFF files (uncompressed) it is called tiff_capture.c ,at the
moment it only stores Y (intensity) component of the image, so you will get
grayscale images, but it is not difficult to convert YUV422P to RGB if you
want, and save it as JPEG. 

So, you can use the program to capture images and store them on SD card.

Abhijeet
Sir, I've been facing the same problem . I want to capture images from
OV9650 which uses /dev/camera character device to capture images . However
when i use your test_capture.c with device name changed from /dev/video0 to
/dev/camera , it gives ioctl error. Can you please help me with how to read
data from non v4l device

Vladimir Fonov
Hello,

as explained at the beginning of the thread the stock cam130 kernel driver
is not V4L compatible. My test_capture.c works only with my custom driver
(which creates /dev/video0 or /dev/video1 device name )

Abhijeet
Sir, 
    I'm novice to programming devices . Can i use 'spcacat' or 'fbshot'
utilities to capture image from my CMOS camera?  Alternatively can you help
me in writing the C code for capturing contents of /dev/camera to store
them in a .ppm file. 
Thanks in advance

Soohong
Hi Vladimir, and all;

I'm developing an image based instrument and thinking the performance of
CAM130 camera is not sufficient for serious applications.
So I was looking for alternative solutions like glass-lens USB webcams or
even different CMOS image sensors to replace the current ov9650 module on
CAM130 board.

 1. USB Webcams - With the current Mini2440 setup, what is the highest
resolution image we can get with USB Webcams? Model and manufacturer?
Sounds like there are compressed and uncompressed image streams and
Mini2440 can handle only uncompressed?

 2. If I end up soldering different CMOS chips on CAM130 board, will that
work? How about configuration register settings? Are these I2C compatible
chips share the same configuration register settings? What kind of changes
will be needed to accomplish this?

I tried my Logitech Quickcam for Notebook Deluxe and Mini2440 doesn't even
recognize it.

Any help would be greatly appreciated!!

Thanks,
Soohong

Vladimir Fonov
Hello,

Abhijeet wrote:
>  I'm novice to programming devices . Can i use 'spcacat' or 'fbshot'
utilities to capture image from my CMOS camera?

No you can't with the stock driver. There is an example included in
http://www.friendlyarm.net/dl.php?file=linux-examples.tgz which reads image
from the /dev/camera and displays on  the screen. 

> CAM130 camera is not sufficient for serious applications
What are "serious" applications? 

Have you tried the custom driver: http://code.google.com/p/s3c2440camera/ ?

1. USB Webcams - mini2440 have USB Full Speed mode only (i.e 12 Mbit/sec)
So, many quality UVC cameras just refuse to work with full resolution on
this mode (I tried with Logitech PRO 9000) 

2. Soldering different CMOS chip - will require changing the driver,
depending on the chip that you use it might range from pretty easy to
impossible. S3C2440 have a peculiar camera interface it can only accept
data in YUV422 format at the rates not faster then 24MHz (if I remember
correctly) Also, interface is 3.3V. 


P.S. I would recommend a gumstix board for "serious" video applications

Abhijeet
Sir, 
     here is the code that i modified to save the captured image in a file
pic.bin instead of displaying it on the LCD. 


#include <sys/time.h>
#include <sys/types.h>
#include <asm/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/mman.h>
#include <errno.h>


#include <linux/fs.h>
#include <linux/kernel.h>
#include "videodev.h"
#include "videodev2.h"
#include <linux/fb.h>

#define V4L2_DEV_NODE      "/dev/camera"
#define FB_DEV_NODE      "/dev/fb/0"



typedef struct fb_var_screeninfo F_VINFO;



static unsigned int fb_grab(int fd, char **fbmem)
{
  
  F_VINFO modeinfo;
  unsigned int length;

  if (ioctl(fd, FBIOGET_VSCREENINFO, &modeinfo) < 0) {
      printf("\n Cannot get screen information ");
    
  }
  length = modeinfo.xres * modeinfo.yres * (modeinfo.bits_per_pixel >> 3);

  printf("fb memory info=xres (%d) x yres (%d), %d bpp\n",
      modeinfo.xres, modeinfo.yres, modeinfo.bits_per_pixel);

  *fbmem = mmap(0, length, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
  if (*fbmem < 0) {
           printf("\n Still couldn't allocate memory ");
    length = 0;
  }
         printf("length of buffer : %d \n ", length );
  return length;
}


static void v4l2_show_on_fb(int fd, char *fbmem, int frames)
{
  int i;
  int ret;
  char preview_buf[240*320*2];
  FILE *img=NULL;
  img=fopen("pic.bin","w");
  printf("\n Opened file for writing ");
    
    if ((ret = read (fd, &preview_buf, 240*320*2)) < 0)
         printf("\n Can't read from file ");   
    if(fprintf(img,preview_buf)==0)
        printf("\nfprintf not working\n");
        printf("\n Before memory copy ");
         memcpy(fbmem, &preview_buf, 240*320*2);
        printf("\n After memory copy ");
         fflush(stdout);  
    
  
  printf("\n");
}

static void fb_ungrab(char **fbmem, unsigned int length)
{
  if (*fbmem)
    munmap(*fbmem, length);
}






int main()
{
 int v4l2_fd=-1,fb_fd=-1;
 char *fbmem = NULL;
 unsigned int fb_length = 0;
 int preview_frames = 180;
 
 v4l2_fd=open(V4L2_DEV_NODE, O_RDWR);
 printf("\n Camera opened successfully in read/write mode ");
 if (v4l2_fd < 0) {
    printf("\n Camera opening failed ");
    exit(0);
  }
 fb_fd=open(FB_DEV_NODE, O_RDWR);
 printf("\n Frame Buffer opened successfully in read/write mode ");
  if (fb_fd < 0) {
    printf("\n Frame Buffer opening failed ");
    exit(0);
  }

  fflush(stdout);
  
  if ((fb_length = fb_grab(fb_fd, &fbmem)) == 0)
   {
    printf("\n Cannot allocate memory for frame buffer ");
    exit(0);
    }
  memset(fbmem, 0, fb_length);
  
  printf("Press Ctrl+'\\' to stop !\n");
  fflush(stdout);
  
  v4l2_show_on_fb(v4l2_fd, fbmem, preview_frames);
  
  printf("\n");
        printf("\n Before closing ");
  if (v4l2_fd > 0)
    close(v4l2_fd);
         printf("\n Closing capture operation \n"); 
  fb_ungrab(&fbmem, fb_length);


return 0;
}

Abhijeet
It works properly but the content of file pic.bin is redundant and is not
the image which is captured by the camera. 
However if i replace /dev/camera with any other normal file such as
/tmp/file1.txt the content can be reproduced accurately. Please help

Vladimir Fonov
Hello,

you can't use fprintf to write binary data into a file. 
replace
if(fprintf(img,preview_buf)==0)

with 

if(fwrite(preview_buf,1,240*320*2,img)!=(240*320*2))


also, add fclose(img) at the end of v4l2_show_on_fb

Abhijeet
Sir, 
   How do i convert the .bin file to .ppm file so that it can be viewed on
my Desktop . (Any other uncompressed format will do inclusing ppm,pgm etc)

Vladimir Fonov
Attachment: bin2ppm.c (602 Byte)
Hello,

something like this (I didn't actually test it) see attached file

ASUStudent
Vladimir,

We are trying to get your capture_test driver to work, but after we install
it we get this error:

[root@FriendlyARM /]# ./test_capture /dev/video0 640 480 test 10
s3c2440camif: Deallocating 4 buffers
s3c2440camif: Allocating 4 buffers, 1310720 for Y , 2x655360 for Cb and Cr
s3c2440camif: Deallocating 4 buffers
s3c2440camif: Allocating 4 buffers, 327680 for Y , 2x163840 for Cb and Cr
Goint to capture frames 640 x 512 format: 422P framesize: 655360
About to capture 10 images to test
**********s3c2440camif: Deallocating 4 buffers
Illegal instruction

Looking at your instructions at http://code.google.com/p/s3c2440camera is
the precompiled kernel already set  up with  "find line
CONFIG_S3C2440_CAMERA=y and replace with CONFIG_S3C2440_CAMERA=m" done, or
do you have an image that is set up with the required changes we can use so
we can just install it to capture the images?

Abhijeet
Sir,
   The bin file gets converted properly to .ppm format but the so formed
ppm file is not visible. It gets blackened out completely.

Abhijeet
Attachment: capture2440.tar.gz (19.66 KB)
I'm hereby uploading the pic.bin and pic.ppm files that were formed as a
result of executing the code. I'm also uploading the code

Jon Ambrose
My CMOS camera doesn't appear in /dev/camera

There is no device. Do I need to install the driver into the directory for
the camera to work. If I try and click on Camera in the apps menu on the
Mini2440, it says device not found, which makes sense as I said theres no
/dev/camera.

Vladimir Fonov
>My CMOS camera doesn't appear in /dev/camera

1. is it actually plugged in?
2. what's the kernel version?
3. anything messages about camera in dmesg ?

Vladimir Fonov
> ASUStudent 
http://s3c2440camera.googlecode.com/files/linux-2.6.32.2-FriendlyARM-zImage
- compiled without camera module

so, if you use this kernel you will have to load modules using insmod
command.

Vladimir Fonov
Attachment: bin2ppm.c (594 Byte)
>The bin file gets converted properly to .ppm format but the so formed
ppm file is not visible. It gets blackened out completely.


I found a bug in bin2ppm.c - see attached file with a fix. See if you get
something useful with it. 

Also, after checking camtest.cpp from FriendlyARM examples I noticed that
the camera resolution should be 640x512 not 320x200 as above. So, you will
have to modify your code accordingly.

Tan
I have just got the CAM130 module. I followed instructions on
http://code.google.com/p/s3c2440camera and ran into following problem while
compilation. 

CC [M]  /root/armmini2440/camera/s3c2440_ov9650.o 
/root/armmini2440/camera/s3c2440_ov9650.c: In function 'ov9650_poweron': 
/root/armmini2440/camera/s3c2440_ov9650.c:123: error: implicit declaration
of function 'S3C2410_GPG' 
make[4]: *** [/root/armmini2440/camera/s3c2440_ov9650.o] Error 1 
make[3]: *** [_module_/root/armmini2440/camera] Error 2 
make[2]: *** [sub-make] Error 2 
make[1]: *** [all] Error 2 
make[1]: Leaving directory `/root/kernel-bin' 
make: *** [default] Error 2 

Please help if possible. Also 2.6.32 kernel if compiled doesn't get loaded
by the usual way (using NOR BIOS) to my NAND. 2.6.29 kernel works just fine
after a successful compilation. My board is 128M and I wish to use it with
VGA 1024x768 display

Astha Aggarwal
Hi,

I am a newbie in OpenCV and v4l. We were using v4l for webcam and capturing
the images. But few devices are not shupported by v4l so we thought to
switch over to some other way then i started working on OpenCV but i read
about OpenCV that it is also using v4l so my question are
1. any webcam device which is not supported by v4l can be supported by
OpenCV??
2. What can be the reason for v4l not to support the webcam devices?

Please help me out...

rwroclaw
Hi Vladimir,

I am working with a senior capstone engineering team at Arizona State
University. We are currently in a jam trying to implement OpenCV on a
FriendlyARM board. I have been reading the forms and I see your name came
up quite a bit with solutions. I was wondering if I could contact you with
some of the problems that we are experiencing. My email is
rwroclaw@asu.edu. Your help would be greatly appreciated.

Thank you

Roman

Rajam AP
Hi all, 

Your forum has helped us a lot. Now we are also trying to capture an image
from camera and we need to both display it on the LCD and also then convert
it to a TIFF file. We are able to do only one of the requirement using
/dev/camera or /dev/video0 respectively. 

Any idea on how we can use the LCD image in RGB format to get converted
into a TIFF file?

Thanks and regards

Rajam

Paul
Hey,
did anyone get this camera working on the 6410 on a different resolution?
Cheers
Paul

Wingz
When i'm trying to modprobe s3c2440camera,

Loading OV9650 driver.........                                        
SCCB address 0x60, manufacture ID 0xFFFF, expect 0x7FA2               
SCCB address 0x60, manufacture ID 0xFFFF, expect 0x7FA2               
No OV9650 found!!!

i get this error. How do we know if the cam130 is on? does it have an power
led on it?

amol
Hi,
I have compiled kernel 2.6.32.2 without s3c2440 camera driver and installed
it on mini2440. I want to install ov9650 camera driver, so how to install
it. I don't know how to send the s3c2440.ko file to mini2440 /bin
directory. please give me any suggestion!

sea
there is a problem on frame buffer. pls let me know , the frame buffer i
used is "/dev/fb/0"  but it is not working.

wibowo
Hi,

I am using CMOS Camera module TCM8230MD instead of CAM130. I think both of
them have same configuration pin but I have tried it at all. Could I
interface the TCM8230MD to friendlyARM? How can I capture image from the
CMOS module?

Anvesh Manne
Hello,

 http://code.google.com/p/s3c2440camera

Can the above driver be used to capture video?

Thanks,
Anvesh