From: Mat Harris <mat.harris@genestate.com>
To: linux-c-programming@vger.kernel.org
Subject: reading the camera device
Date: Fri, 29 Nov 2002 10:30:43 +0000 [thread overview]
Message-ID: <20021129103043.GA24283@genestate.com> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 434 bytes --]
ok, i have this little bit of code to read the camera device and return the
buffer to another function for writing to a ppm image. the problem is that
when it gets to the read function, it hangs and never resumes. obviously
there is a problem somewhere in the way of length of reading the bytes in.
the program is attached.
--
Mat Harris OpenGPG Public Key ID: C37D57D9
mat.harris@genestate.com matthewh.genestate.com
[-- Attachment #1.2: grab.c --]
[-- Type: text/plain, Size: 1601 bytes --]
/*Spiros Ioannou 2/2000 */
/*sivann@softlab.ece.ntua.gr*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <linux/types.h>
#include <errno.h>
/*#include <linux/videodev.h>*/
#include "../conf.h"
void save_ppm(char *filename, unsigned char *pic);
int main()
{
int dev; /* the device we will use */
int len;
char device[FILENAME_SIZE] = "/dev/video0";
unsigned char pic[MAX_RGBA_IMAGE_SIZE];
char filename[FILENAME_SIZE] = "./test.ppm";
dev = open (device, O_RDWR);
if (dev < 0)
{
perror(device);
exit(1);
}
fprintf(stderr, "about to read\n");
len = read(dev, pic, MAX_RGBA_IMAGE_SIZE);
if (len == 0 || len == -1)
{
fprintf(stderr, "error reading camera device\n");
exit(0);
}
fprintf(stderr, "read\n");
/*while((len = read(dev, pic, MAX_RGBA_IMAGE_SIZE)) <= 0)
{
if(errno != 0 && errno != EINTR)
{
fprintf(stderr, "Error read image\n");
exit(0);
}
}*/
save_ppm(filename, pic);
exit(0);
}
void save_ppm(char *filename, unsigned char *pic)
{
FILE *outfile;
unsigned char buff[3];
int i;
if (!(outfile=fopen(filename,"w"))) {
perror(filename);
exit(errno);
};
fprintf (outfile, "P6\n%d %d\n%d\n", 640, 480, 255);
for (i = 0; i < 640*480*3; i+=3) {
buff[0] = pic[i]; /* r */
buff[1] = pic[i+1]; /* g */
buff[2] = pic[i+2]; /* b */
fwrite (buff, 1, 3, outfile);
}
fclose(outfile);
}
[-- Attachment #1.3: conf.h --]
[-- Type: text/plain, Size: 771 bytes --]
/************************************************
* this is the config file containing defaults *
* for the camera program. all defaults are *
* controlled with preprocessor macros *
************************************************/
#define FILENAME_SIZE 20 /* char size for holding filenames */
#define DEFAULT_NOISE_THREASHOLD 60 /* level of noise */
#define DEFAULT_PIXEL_THREASHOLD 1500 /* number of changed pixels */
#define X_AXIS_IMAGE_SIZE 640 /* work it out */
#define Y_AXIS_IMAGE_SIZE 480 /* ditto */
#define DAY_LIGHT_LEVEL 180 /* mark to differentiate between day and night */
#define TIMEOUT_LEN 1000 /* ??? - doesn't seem to be used anywhere else */
#define MAX_RGBA_IMAGE_SIZE ((640*480*4)+256) /* maximum size for capturing an image */
[-- Attachment #2: Type: application/pgp-signature, Size: 232 bytes --]
reply other threads:[~2002-11-29 10:30 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20021129103043.GA24283@genestate.com \
--to=mat.harris@genestate.com \
--cc=linux-c-programming@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).