In fact, there is always an idea, is to design a remote video surveillance software, the current own hardware includes: mini2440 Development Board, Vedon Teacher's camera module ov7740, of course, this camera provides a mini2440 based on the reading and display functions, But I do not provide the network display function, for this, I want to add this function, have this idea, also comes from the Mjpg-streamer project design idea.
Design ideas as follows:
mini2440 read the camera data, and then through the UDP broadcast transmission to the host computer, the host computer through the QT implementation of data display.
mini2440 Source code:
This code is based on Vedon teacher's VIDEO2LCD modification, changes as follows:
/* VIDEO2LCD </dev/video0,1,... > */int main (int argc, char **argv) {//unsigned char test = 0;
int ret;
int sockfd = 0x00;
int ierror;
T_videodevice Tvideodevice;
Pt_videoconvert Ptvideoconvert;
int ipixelformatofvideo;
int ipixelformatofdisp;
Pt_videobuf ptvideobufcur;
T_videobuf Tvideobuf;
T_videobuf Tconvertbuf;
T_videobuf Tzoombuf;
T_videobuf Tframebuf;
int ilcdwidth;
int ilcdheight;
int ilcdbpp;
int itopleftx;
int itoplefty;
float k;
uint16_t timeout = 0xFFFF;
U8 Ipaddr[4] = {192,168,1,100};
if (argc! = 2) {printf ("usage:\n");
printf ("%s </dev/video0,1,... >\n", argv[0]);
return-1;
}/*network init*/ret = net_udp_init (Simu_port, timeout);
if (Ret < 0) {dbg_printf ("Net_udp_init error!\n");
return-1;
}else{SOCKFD = ret;
}/* A series of initialization */* Registered display device */displayinit (); /* May support multiple display setsOptional: Select and initialize the specified display device */Selectandinitdefaultdispdev ("FB");
Getdispresolution (&ilcdwidth, &ilcdheight, &ILCDBPP);
Getvideobuffordisplay (&TFRAMEBUF);
Ipixelformatofdisp = Tframebuf.ipixelformat;
Videoinit ();
Ierror = Videodeviceinit (argv[1], &tvideodevice);
if (ierror) {dbg_printf ("Videodeviceinit for%s error!\n", argv[1]);
return-1;
} Ipixelformatofvideo = Tvideodevice.ptopr->getformat (&tvideodevice);
Videoconvertinit ();
Ptvideoconvert = Getvideoconvertforformats (Ipixelformatofvideo, Ipixelformatofdisp);
if (NULL = = Ptvideoconvert) {dbg_printf ("Can not be support this format convert\n");
return-1;
}/* Start the camera device */ierror = Tvideodevice.ptopr->startdevice (&tvideodevice);
if (ierror) {dbg_printf ("Startdevice for%s error!\n", argv[1]);
return-1;
} memset (&tvideobuf, 0, sizeof (TVIDEOBUF)); memset (&tconvertbuf, 0, sizeof (TCONVERTBUF));
Tconvertbuf.ipixelformat = Ipixelformatofdisp;
TCONVERTBUF.TPIXELDATAS.IBPP = ILCDBPP;
memset (&tzoombuf, 0, sizeof (TZOOMBUF));
Puttest ();
while (1) {//char buf[255];//FILE *FP;
time_t ts;
struct TM *t;
Time (&ts);
t = gmtime (&ts); sprintf (buf, "video-%d-%d-%d--%02d-%02d-%02d.jpg", t->tm_year,t->tm_mon,t->tm_mday,t->tm_hour,t-
>TM_MIN,T->TM_SEC);
fp = fopen (buf, "w");
if (fp = = NULL)//{//dbg_printf ("fopen file error!\n");//return-1;//}
/* Read in camera data */Ierror = Tvideodevice.ptopr->getframe (&tvideodevice, &tvideobuf);
if (ierror) {dbg_printf ("GetFrame for%s error!\n", argv[1]);
return-1;
} ptvideobufcur = &tVideoBuf; dbg_printf ("ptvideobufcur->tpixeldatas.iwidth:%d ptvideobufcur->tpixeldatas.iheight:%d total:%d\n ", ptvideobufcur->tpixeldatas.iwidth,ptvideobufcur->tpixeldatas.iheight,ptvideobufcur-
>tpixeldatas.itotalbytes);
Fwrite (TVIDEOBUF.TPIXELDATAS.AUCPIXELDATAS,TVIDEOBUF.TPIXELDATAS.ITOTALBYTES,1,FP);
Fclose (FP);
ret = Net_udp_send (SOCKFD, TVideoBuf.tPixelDatas.aucPixelDatas, TVideoBuf.tPixelDatas.iTotalBytes, ipaddr, 9000);
if (Ret < 0) {dbg_printf ("Net_udp_send error!\n"); if (ipixelformatofvideo! = ipixelformatofdisp) {/* conversion to RGB */ierror = PTVIDEOC
Onvert->convert (&tvideobuf, &tconvertbuf);
dbg_printf ("Convert%s, ret =%d\n", Ptvideoconvert->name, Ierror);
if (ierror) {dbg_printf ("Convert for%s error!\n", argv[1]);
return-1;
} ptvideobufcur = &tConvertBuf; }//dbg_printf ("ptvideobufcur->tpixeldatas.iwidth:%d PtvideobuFcur->tpixeldatas.iheight:%d\n ", Ptvideobufcur->tpixeldatas.iwidth,ptvideobufcur->tpixeldatas.iheight)
; /* If the image resolution is larger than the LCD, zoom */if (Ptvideobufcur->tpixeldatas.iwidth > Ilcdwidth | | ptvideobufcur->tpixeldatas.ih Eight > Ilcdheight) {/* Determines the scaled resolution///////////* To zoom the picture proportionally to the Videomem, centering * 1. First figure out Scaled size */k = (float) ptvideobufcur->tpixeldatas.iheight/ptvideobufcur->tpixeldatas.iwidth
;
TZoomBuf.tPixelDatas.iWidth = Ilcdwidth;
TZoomBuf.tPixelDatas.iHeight = Ilcdwidth * k; if (TZoomBuf.tPixelDatas.iHeight > Ilcdheight) {tZoomBuf.tPixelDatas.iWidth = Ilcdheight
K
TZoomBuf.tPixelDatas.iHeight = Ilcdheight;
} tZoomBuf.tPixelDatas.iBpp = ILCDBPP;
TZoomBuf.tPixelDatas.iLineBytes = TZoomBuf.tPixelDatas.iWidth * TZOOMBUF.TPIXELDATAS.IBPP/8; tzoombuf.tPixeldatas.itotalbytes = tZoomBuf.tPixelDatas.iLineBytes * tZoomBuf.tPixelDatas.iHeight; if (!tzoombuf.tpixeldatas.aucpixeldatas) {TZoomBuf.tPixelDatas.aucPixelDatas = malloc (Tzoombu
F.tpixeldatas.itotalbytes);
} piczoom (&ptvideobufcur->tpixeldatas, &tzoombuf.tpixeldatas);
Ptvideobufcur = &tZoomBuf; }/* Merge into Framebuffer */* To calculate the upper-left coordinate of the center display */ITOPLEFTX = (ilcdwidth-ptvideobufcur->tpixeldata
S.iwidth)/2;
Itoplefty = (ilcdheight-ptvideobufcur->tpixeldatas.iheight)/2;
Picmerge (ITOPLEFTX, Itoplefty, &ptvideobufcur->tpixeldatas, &tframebuf.tpixeldatas);
Flushpixeldatastodev (&tframebuf.tpixeldatas);
Flushpixeldatastodev (&ptvideobufcur->tpixeldatas);
Ierror = Tvideodevice.ptopr->putframe (&tvideodevice, &tvideobuf); if (ierror) {dbg_printf ("Putframe foR%s error!\n ", argv[1]);
return-1;
}//fclose (FP);
/* Swipe the framebuffer data to the LCD to display the */} return 0;
}
Git code library: https://git.oschina.net/pengrui2009/video2lcd.git
QT Display source code:
The UDP broadcast receives the data and translates it into a qimage display:
void Imageviewer::p roc_udp_data ()
{
qimage image;//(databuf, +, +, QIMAGE::FORMAT_RGB16);
uint32_t Len;
The receiving team
is included in the team while (Udpsocket->haspendingdatagrams ())
{
len = udpsocket->readdatagram (char *) BUF, 65535);
if (len)
{
image.loadfromdata (buf, Len);
Imagelabel->setpixmap (qpixmap::fromimage (image));
Scalefactor = 1.0;
Printact->setenabled (true);
Fittowindowact->setenabled (true);
Updateactions ();
if (!fittowindowact->ischecked ())
imagelabel->adjustsize ();
Fittowindow ();
Scrollarea->setwidgetresizable (True);}}}
Git code library: https://git.oschina.net/pengrui2009/video2lcd-qt.git