android4.0 USB Camera Instance (quad) CMOS

Source: Internet
Author: User

The previous article said under the USB camera UVC standard by the way CMOS do the same operation on the basic one to the previous HAL layer I have provided the relevant CMOS interface

Jniexport Jint Jnicall Java_com_dao_usbcam_fimcgzsd_yuvtorgb

If using the same processing image as UVC does not appear, so in a different way it is used in the ICOOL210 board test if using CMOS also need to modify some of the HAL layer modified as follows

First add a function as follows

int select_input (int input) {int ret;ret = IOCTL (FD, Vidioc_s_input, &input); if (ret) {printf ("Xioctl vidioc_s_input F Ailed+++++\n ");}   return ret;}
In Init calls Init to modify the following

Jniexport jint jnicall java_com_dao_usbcam_fimcgzsd_init (jnienv * env, Jclass obj, jint width, jint height,jint Numbuf,jin T ctype) {int Ret;int i;bufnum = numbuf;mwidth = Width;mheight = Height;c_type = ctype;struct V4l2_format fmt;struct v4l2_c    Apability cap;if (C_type = = 2) select_input (0); else if (C_type = 3) select_input (1);    RET = IOCTL (FD, Vidioc_querycap, &cap);        if (Ret < 0) {LOGE ("%d:vidioc_querycap failed\n", __line__);    return-1; } if (! (        Cap.capabilities & V4l2_cap_video_capture) {LOGE ("%d:no CAPTURE devices\n", __line__);    return-1; }memset (&fmt, 0, sizeof (FMT)), Fmt.type = v4l2_buf_type_video_capture;if (C_type > 0) Fmt.fmt.pix.pixelformat = V4l2_pix_fmt_yuyv;elsefmt.fmt.pix.pixelformat = V4l2_pix_fmt_rgb565;if (C_type > 1) {Fmt.fmt.pix.field = V4l2_field _none;//v4l2_field_interlaced;//v4l2_field_none;fmt.fmt.pix.priv = 1;} Fmt.fmt.pix.width = Width;fmt.fmt.pix.height = height;if (IOCTL (FD, VIDIOC_S_FMT, &fmt) &LT    0) {LOGE ("++++%d:set format failed\n", __line__); return-1;}    struct V4l2_requestbuffers req;    Req.count = Numbuf;    Req.type = v4l2_buf_type_video_capture;    Req.memory = V4l2_memory_mmap;    RET = IOCTL (FD, VIDIOC_REQBUFS, &req);        if (Ret < 0) {LOGE ("++++%d:vidioc_reqbufs failed\n", __line__);    return-1;    } buffers = Calloc (req.count, sizeof (*buffers));    if (!buffers) {LOGE ("++++%d Out of memory\n", __line__); return-1; }for (i = 0; i< bufnum; ++i) {memset (&v4l2_buf, 0, sizeof (V4L2_BUF)); v4l2_buf.type = V4l2_buf_type_video_capture;   V4l2_buf.memory = V4l2_memory_mmap;v4l2_buf.index = I;ret = IOCTL (FD, VIDIOC_QUERYBUF, &v4l2_buf); if (Ret < 0) {   LOGE ("+++%d:vidioc_querybuf failed\n", __line__); return-1;}                                     Buffers[i].length = V4l2_buf.length;if ((Buffers[i].start = (char *) mmap (0, V4l2_buf.length, Prot_read | Prot_write, map_shared, FD, V4L2_BUF.M.OFfset)) < 0) {LOGE ("%d:mmap () failed", __line__); return-1;}} RGB = (int *) malloc (sizeof (int) * (mwidth*mheight)); ybuf = (int *) malloc (sizeof (int) * (mwidth*mheight)); return 0;}

The modification place is not many here when the C_type is 2 for the CMOS interface Channel 1 is 3 when the Channel 2

At the same time

void Yuyv422torgb (unsigned char *src,int *mrgb)

Finally need to modify under the test process found red and blue reversed so the last

        *lrgb++ = 0xff000000 | b1<<16 | g1<<8 | R1;          *lrgb++ = 0xff000000 | b2<<16 | g2<<8 | R2;  
Revision changed to

*lrgb++ = 0xff000000 | r1<<16 | g1<<8 | b1;*lrgb++ = 0xff000000 | r2<<16 | g2<<8 | B2;
The relevant changes in the final application are as follows

Class Startthread extends Thread {@Overridepublic void Run () {//TODO auto-generated method Stub//super.run (); while (true) {index = FIMCGZSD.DQBUF (Mdata), if (Index < 0) {OnDestroy (); break;} Switch (CType) {case 0:mhandler.post (mupdateui); bitmap = Bitmapfactory.decodebytearray (mdata, 0, Width * height); FIMCGZSD.QBUF (index); break;case 1:fimcgzsd.pixeltobmp (BMP); Mhandler.post (mupdateui); bitmap = bmp; FIMCGZSD.QBUF (index); break;case 2:case 3:                    Fimcgzsd.yuvtorgb (Mdata, RGB);                     Mhandler.post (MUPDATEUI);                    Bitmap = Bitmap.createbitmap (rgb,width,height,bitmap.config.argb_8888);                    FIMCGZSD.QBUF (index); break;}}}
The final application is modified as follows here is mainly to implement the functional interface is relatively simple



The CMOS effect is as follows



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.