added width, height parameters to setFormat(), working to set YUYV format but not RGB formats I tried
git-svn-id: svn://anubis/misc/WebcamTracker@127 bd8a9e45-a331-0410-811e-c64571078777
This commit is contained in:
parent
d7d82a28c4
commit
c261550290
@ -59,7 +59,7 @@ bool WebcamTracker::open(const char * device)
|
||||
|
||||
void WebcamTracker::start()
|
||||
{
|
||||
setFormat();
|
||||
setFormat(640, 480);
|
||||
requestBuffers(20);
|
||||
for (int i = 0; i < m_numbufs; i++)
|
||||
{
|
||||
@ -240,7 +240,7 @@ WebcamTracker::~WebcamTracker()
|
||||
}
|
||||
}
|
||||
|
||||
void WebcamTracker::setFormat()
|
||||
void WebcamTracker::setFormat(int width, int height)
|
||||
{
|
||||
v4l2_format fmt;
|
||||
memset(&fmt, 0, sizeof(fmt));
|
||||
@ -248,24 +248,28 @@ void WebcamTracker::setFormat()
|
||||
int ret = ioctl(m_fd, VIDIOC_G_FMT, &fmt);
|
||||
if (ret != 0)
|
||||
{
|
||||
cerr << "Warning: VIDIOC_G_FMT ioctl failed, errno " << errno;
|
||||
if (errno == EBUSY)
|
||||
int err = errno;
|
||||
cerr << "Warning: VIDIOC_G_FMT ioctl failed, errno " << err;
|
||||
if (err == EBUSY)
|
||||
cerr << " (EBUSY)";
|
||||
if (errno == EINVAL)
|
||||
if (err == EINVAL)
|
||||
cerr << " (EINVAL)";
|
||||
cerr << endl;
|
||||
}
|
||||
cerr << "width: " << fmt.fmt.pix.width << endl;
|
||||
cerr << "height: " << fmt.fmt.pix.height << endl;
|
||||
cerr << "pixelformat: ";
|
||||
for (int s = 0; s < 32; s += 8)
|
||||
cerr << (char)((fmt.fmt.pix.pixelformat >> s) & 0xFF);
|
||||
cerr << endl;
|
||||
cerr << "field: " << fmt.fmt.pix.field << endl;
|
||||
cerr << "bytesperline: " << fmt.fmt.pix.bytesperline << endl;
|
||||
fmt.fmt.pix.width = width;
|
||||
fmt.fmt.pix.height = height;
|
||||
fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
|
||||
fmt.fmt.pix.bytesperline = width * 2;
|
||||
fmt.fmt.pix.sizeimage = fmt.fmt.pix.bytesperline * height;
|
||||
ret = ioctl(m_fd, VIDIOC_S_FMT, &fmt);
|
||||
if (ret != 0)
|
||||
{
|
||||
cerr << "Warning: VIDIOC_S_FMT ioctl failed, errno " << errno << endl;
|
||||
int err = errno;
|
||||
cerr << "Warning: VIDIOC_S_FMT ioctl failed, errno " << err;
|
||||
if (err == EBUSY)
|
||||
cerr << " (EBUSY)";
|
||||
if (err == EINVAL)
|
||||
cerr << " (EINVAL)";
|
||||
cerr << endl;
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ class WebcamTracker
|
||||
void dequeueBuffer(v4l2_buffer * dqbuf);
|
||||
void unmapBuffer(int i);
|
||||
void freeBuffers();
|
||||
void setFormat();
|
||||
void setFormat(int width, int height);
|
||||
|
||||
bool m_open;
|
||||
int m_fd;
|
||||
|
Loading…
x
Reference in New Issue
Block a user