现在的位置: 首页 > 综合 > 正文

通过html和cgi实现拍照显示功能

2013年08月31日 ⁄ 综合 ⁄ 共 3406字 ⁄ 字号 评论关闭

作者:任程明,华清远见嵌入式培训中心讲师。

1. 编写html网页 :video.html。

网页内容如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
         <html xmlns="http://www.w3.org/1999/xhtml">
         <head>
         <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
         <title>video</title>
         <style type="text/css">
         <!--
          .STYLE1 {
         font-size: xx-large;
         font-style: italic;
         color: #0033FF;
          }
          -->
          </style>
          </head>
         <body>
         <table width="652" height="163" background="images/h3.png" border="0" align="center">
         <tr>
         <td><span class="STYLE1">example</span></td>
         </tr>
         </table><tr>
          <div align="center">video</div>
          <table width="500" align="center" height="561" border="0">
          <tr>

(1)前期移植了mjpg-streamer 来获得视频流。

(2)通过“ http://192.168.1.200:8080/?action=stream”来查看视频流的捕获情况。

<td height="500"><img src="http://192.168.1.200:8080/?action=stream"/></td>
          </tr>
          <tr>
         <td height="55"><form id="form3" name="form3" method="post" action="./cgi-bin/capture.cgi">
         <table width="500" border="1" bgcolor="#CCFFFF" bordercolor="#5500FF">
         <tr>
         <td width="195"><p>
          <label></label>
         <a href="choose.html">choose /a><br />
         </p></td>
         <td width="289">
         <div align="center">

(3)前期移植了boa服务器。

(4)点击网页上的“单拍”按钮后,调用服务器中的cgi:picture.cgi,对图像数据进行采集。

<input type="submit" name="button3" id="button3" value="picture" />&nbsp;&nbsp;&nbsp;<a href="cgi-bin/picture.cgi">单拍 </a></div></td>
         </tr>
          </table>
          </form></td>
          </tr>
          </table>
          </body>
          </html>

2. 用于获取图片的cgi程序:picture.c .

Cgi程序内容如下:

#include <stdio.h>
        #include"cgic.h"
        #include <string.h>
        #include <stdlib.h>
        #include <unistd.h>
        #include <errno.h>
        #include <stddef.h>
        #include <sys/stat.h>
        #include <dirent.h>
        #include <iconv.h>
        #include <sys/types.h>
         #include <sys/wait.h>
         int cgiMain()
         {

(1)使用文件系统中的文件夹相应的操作变量:

DIR *dir;
         struct dirent *dirp;

(2)cgi程序将相关的网页信息到浏览器中显示:

cgiHeaderContentType("text/html");
         fprintf(cgiOut, "<HTML>\n");
         fprintf(cgiOut, "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
         fprintf(cgiOut, " <html xmlns=\"http://www.w3.org/1999/xhtml\"><head>");
         fprintf(cgiOut, "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />");
         fprintf(cgiOut, "<link rel=\"stylesheet\" href=\"../images/style.css\" type=\"text/css\" /> <title>history Picture</title></head>");
         fprintf(cgiOut, "<body>");
         fprintf(cgiOut, "<H1 align=\"left\">history Picture:<H1>");

(3)编写cgi程序读取文件系统中的图片文件

if((dir = opendir("../pice/")) == NULL)
         {
         perror("fail to opendir");
         return -1;
         }
         if(dir != NULL)
         {
         while((dirp = readdir(dir)) != NULL)
         {
         if(dirp->d_name[0] == '.') continue;
         fprintf(cgiOut, "<div align=\"center\">");
         fprintf(cgiOut,"%s",dirp->d_name);
          fprintf(cgiOut, "</div>");

(4)通过cgi程序显示图片文件到网页:

fprintf(cgiOut, "<div align=\"center\"><img src=\"../pice/%s\" width=\"320\" height=\"240\" />",dirp->d_name);
         fprintf(cgiOut, "</div>");
         }
         }
         fprintf(cgiOut, "</BODY></HTML>");
         return 0;
         }

嵌入式及3G相关资源及学习请点击:嵌入式开发视频 android开发视频 android培训 3G培训 QT培训 QT开发视频 物联网培训 物联网技术视频 嵌入式学习  

抱歉!评论已关闭.