?? cmvision1.2.html
字號:
#<B><FONT COLOR="#5F9EA0">define</FONT></B> <FONT COLOR="#B8860B">DEFAULT_VIDEO_DEVICE</FONT> <B><FONT COLOR="#BC8F8F">"/dev/video"</FONT></B>#<B><FONT COLOR="#5F9EA0">define</FONT></B> <FONT COLOR="#B8860B">VIDEO_STANDARD</FONT> <B><FONT COLOR="#BC8F8F">"NTSC"</FONT></B>#<B><FONT COLOR="#5F9EA0">ifdef</FONT></B> <FONT COLOR="#B8860B">USE_METEOR</FONT>#<B><FONT COLOR="#5F9EA0">define</FONT></B> <FONT COLOR="#B8860B">DEFAULT_VIDEO_FORMAT</FONT> V4L2_PIX_FMT_UYVY#<B><FONT COLOR="#5F9EA0">else</FONT></B>#<B><FONT COLOR="#5F9EA0">define</FONT></B> <FONT COLOR="#B8860B">DEFAULT_VIDEO_FORMAT</FONT> V4L2_PIX_FMT_YUYV#<B><FONT COLOR="#5F9EA0">endif</FONT></B>#<B><FONT COLOR="#5F9EA0">define</FONT></B> <FONT COLOR="#B8860B">DEFAULT_IMAGE_WIDTH</FONT> 320#<B><FONT COLOR="#5F9EA0">define</FONT></B> <FONT COLOR="#B8860B">DEFAULT_IMAGE_HEIGHT</FONT> 240<I><FONT COLOR="#B22222">// if you get a message like "DQBUF returned error", "DQBUF error: invalid"</FONT></I><I><FONT COLOR="#B22222">// then you need to use a higher value for STREAMBUFS or process frames faster</FONT></I>#<B><FONT COLOR="#5F9EA0">define</FONT></B> <FONT COLOR="#B8860B">STREAMBUFS</FONT> 8class capture{ <B><FONT COLOR="#228B22">struct</FONT></B> vimage_t{ v4l2_buffer vidbuf; <B><FONT COLOR="#228B22">char</FONT></B> *data; }; <B><FONT COLOR="#228B22">int</FONT></B> vid_fd; <I><FONT COLOR="#B22222">// video device</FONT></I> vimage_t vimage[STREAMBUFS]; <I><FONT COLOR="#B22222">// buffers for images</FONT></I> <B><FONT COLOR="#228B22">struct</FONT></B> v4l2_format fmt; <I><FONT COLOR="#B22222">// video format request</FONT></I> <B><FONT COLOR="#228B22">unsigned</FONT></B> <B><FONT COLOR="#228B22">char</FONT></B> *current; <I><FONT COLOR="#B22222">// most recently captured frame</FONT></I> stamp_t timestamp; <I><FONT COLOR="#B22222">// frame time stamp</FONT></I> <B><FONT COLOR="#228B22">int</FONT></B> width,height; <I><FONT COLOR="#B22222">// dimensions of video frame</FONT></I> <B><FONT COLOR="#228B22">struct</FONT></B> v4l2_buffer tempbuf; bool captured_frame;<B><FONT COLOR="#5F9EA0">public</FONT></B>: capture() {vid_fd = 0; current=NULL; captured_frame = false;} ~capture() {close();} bool initialize(<B><FONT COLOR="#228B22">char</FONT></B> *device,<B><FONT COLOR="#228B22">int</FONT></B> nwidth,<B><FONT COLOR="#228B22">int</FONT></B> nheight,<B><FONT COLOR="#228B22">int</FONT></B> nfmt); bool initialize(<B><FONT COLOR="#228B22">int</FONT></B> nwidth,<B><FONT COLOR="#228B22">int</FONT></B> nheight) {<B><FONT COLOR="#A020F0">return</FONT></B>(initialize(NULL,nwidth,nheight,0));} bool initialize() {<B><FONT COLOR="#A020F0">return</FONT></B>(initialize(NULL,0,0,0));} <B><FONT COLOR="#228B22">void</FONT></B> close(); <B><FONT COLOR="#228B22">unsigned</FONT></B> <B><FONT COLOR="#228B22">char</FONT></B> *captureFrame(<B><FONT COLOR="#228B22">int</FONT></B> &index); <B><FONT COLOR="#228B22">unsigned</FONT></B> <B><FONT COLOR="#228B22">char</FONT></B> *captureFrame(); <B><FONT COLOR="#228B22">void</FONT></B> releaseFrame(<B><FONT COLOR="#228B22">unsigned</FONT></B> <B><FONT COLOR="#228B22">char</FONT></B>* frame, <B><FONT COLOR="#228B22">int</FONT></B> index); <B><FONT COLOR="#228B22">unsigned</FONT></B> <B><FONT COLOR="#228B22">char</FONT></B> *getFrame() {<B><FONT COLOR="#A020F0">return</FONT></B>(current);} stamp_t getFrameTime() {<B><FONT COLOR="#A020F0">return</FONT></B>(timestamp);} <B><FONT COLOR="#228B22">int</FONT></B> getWidth() {<B><FONT COLOR="#A020F0">return</FONT></B>(width);} <B><FONT COLOR="#228B22">int</FONT></B> getHeight() {<B><FONT COLOR="#A020F0">return</FONT></B>(height);}};#<B><FONT COLOR="#5F9EA0">endif</FONT></B> // <FONT COLOR="#B8860B">__CAPTURE_H__</FONT></PRE><HR><A NAME="file6"><H1>include/cmvision.h 6/22</H1>[<A HREF="#top">top</A>][<A HREF="#file5">prev</A>][<A HREF="#file7">next</A>]<PRE><I><FONT COLOR="#B22222">/*========================================================================= CMVision.h ------------------------------------------------------------------------- API definition for the CMVision real time Color Machine Vision library ------------------------------------------------------------------------- Copyright 1999, 2000 #### ### ### ## ## ## #### ## ### ## ## James R. Bruce ## ####### ## ## ## ## ## ## ## ###### School of Computer Science ## ## # ## ## ## ## ### ## ## ## ## ### Carnegie Mellon University #### ## ## ### ## #### ## ### ## ## ------------------------------------------------------------------------- This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA =========================================================================*/</FONT></I>#<B><FONT COLOR="#5F9EA0">ifndef</FONT></B> <FONT COLOR="#B8860B">__CMVISION_H__</FONT>#<B><FONT COLOR="#5F9EA0">define</FONT></B> <FONT COLOR="#B8860B">__CMVISION_H__</FONT><I><FONT COLOR="#B22222">// uncomment if your compiler supports the "restrict" keyword</FONT></I><I><FONT COLOR="#B22222">// #define restrict __restrict__</FONT></I>#<B><FONT COLOR="#5F9EA0">define</FONT></B> <FONT COLOR="#B8860B">restrict</FONT>#<B><FONT COLOR="#5F9EA0">include</FONT></B> <B><FONT COLOR="#BC8F8F"><stdlib.h></FONT></B>#<B><FONT COLOR="#5F9EA0">include</FONT></B> <B><FONT COLOR="#BC8F8F"><string.h></FONT></B>#<B><FONT COLOR="#5F9EA0">include</FONT></B> <B><FONT COLOR="#BC8F8F"><stdio.h></FONT></B><I><FONT COLOR="#B22222">/*Ultra-fast intro to processing steps: - Color segmentation - load / save - set new values - process frame - Connected Regions - RLE - merge - extract blobs - separate blobs - sort blobs - merge blobs - Blob merging (not currently in release) - merge by area occupiedOptions File Format: (RGB merge name)[Colors](00,00,00) 0.95 'Orange'(00,00,00) 0.00 'Pink'(00,00,00) 0.00 'Red'(00,00,00) 0.00 'DarkBlue'(00,00,00) 0.00 'Blue'[Thresholds](<lo>:<hi>,<lo>:<hi>,<lo>:<hi>)(<lo>:<hi>,<lo>:<hi>,<lo>:<hi>)(<lo>:<hi>,<lo>:<hi>,<lo>:<hi>)*/</FONT></I>#<B><FONT COLOR="#5F9EA0">define</FONT></B> <FONT COLOR="#B8860B">CMV_COLOR_LEVELS</FONT> 256#<B><FONT COLOR="#5F9EA0">define</FONT></B> <FONT COLOR="#B8860B">CMV_MAX_COLORS</FONT> 32<I><FONT COLOR="#B22222">// sets tweaked optimal values for image size</FONT></I>#<B><FONT COLOR="#5F9EA0">define</FONT></B> <FONT COLOR="#B8860B">CMV_DEFAULT_WIDTH</FONT> 320#<B><FONT COLOR="#5F9EA0">define</FONT></B> <FONT COLOR="#B8860B">CMV_DEFAULT_HEIGHT</FONT> 240<I><FONT COLOR="#B22222">// values may need tweaked, although these seem to work usually</FONT></I>#<B><FONT COLOR="#5F9EA0">define</FONT></B> <FONT COLOR="#B8860B">CMV_MAX_RUNS</FONT> (CMV_DEFAULT_WIDTH * CMV_DEFAULT_HEIGHT) / 4#<B><FONT COLOR="#5F9EA0">define</FONT></B> <FONT COLOR="#B8860B">CMV_MAX_REGIONS</FONT> CMV_MAX_RUNS / 4#<B><FONT COLOR="#5F9EA0">define</FONT></B> <FONT COLOR="#B8860B">CMV_MIN_AREA</FONT> 4#<B><FONT COLOR="#5F9EA0">define</FONT></B> <FONT COLOR="#B8860B">CMV_NONE</FONT> ((unsigned)(-1))#<B><FONT COLOR="#5F9EA0">ifndef</FONT></B> <FONT COLOR="#B8860B">NULL</FONT>#<B><FONT COLOR="#5F9EA0">define</FONT></B> <FONT COLOR="#B8860B">NULL</FONT> (0)#<B><FONT COLOR="#5F9EA0">endif</FONT></B><B><FONT COLOR="#228B22">struct</FONT></B> yuv{ <B><FONT COLOR="#228B22">unsigned</FONT></B> <B><FONT COLOR="#228B22">char</FONT></B> y,u,v;};<B><FONT COLOR="#228B22">struct</FONT></B> yuv422{ <B><FONT COLOR="#228B22">unsigned</FONT></B> <B><FONT COLOR="#228B22">char</FONT></B> y1,u,y2,v;};<B><FONT COLOR="#228B22">struct</FONT></B> uyvy{ <B><FONT COLOR="#228B22">unsigned</FONT></B> <B><FONT COLOR="#228B22">char</FONT></B> u,y1,v,y2;};#<B><FONT COLOR="#5F9EA0">ifdef</FONT></B> <FONT COLOR="#B8860B">USE_METEOR</FONT> <B><FONT COLOR="#228B22">typedef</FONT></B> <B><FONT COLOR="#228B22">struct</FONT></B> uyvy image_pixel;#<B><FONT COLOR="#5F9EA0">else</FONT></B> <B><FONT COLOR="#228B22">typedef</FONT></B> <B><FONT COLOR="#228B22">struct</FONT></B> yuv422 image_pixel;#<B><FONT COLOR="#5F9EA0">endif</FONT></B>#<B><FONT COLOR="#5F9EA0">ifndef</FONT></B> <FONT COLOR="#B8860B">RGB_STRUCT</FONT>#<B><FONT COLOR="#5F9EA0">define</FONT></B> <FONT COLOR="#B8860B">RGB_STRUCT</FONT><B><FONT COLOR="#228B22">struct</FONT></B> rgb{ <B><FONT COLOR="#228B22">unsigned</FONT></B> <B><FONT COLOR="#228B22">char</FONT></B> red,green,blue;};#<B><FONT COLOR="#5F9EA0">endif</FONT></B><I><FONT COLOR="#B22222">// Options for level of processing</FONT></I><I><FONT COLOR="#B22222">// use enable()/disable() to change </FONT></I>#<B><FONT COLOR="#5F9EA0">define</FONT></B> <FONT COLOR="#B8860B">CMV_THRESHOLD</FONT> 0x01#<B><FONT COLOR="#5F9EA0">define</FONT></B> <FONT COLOR="#B8860B">CMV_COLOR_AVERAGES</FONT> 0x02#<B><FONT COLOR="#5F9EA0">define</FONT></B> <FONT COLOR="#B8860B">CMV_DUAL_THRESHOLD</FONT> 0x04#<B><FONT COLOR="#5F9EA0">define</FONT></B> <FONT COLOR="#B8860B">CMV_DENSITY_MERGE</FONT> 0x08#<B><FONT COLOR="#5F9EA0">define</FONT></B> <FONT COLOR="#B8860B">CMV_VALID_OPTIONS</FONT> 0x0Fclass CMVision{<B><FONT COLOR="#5F9EA0">public</FONT></B>: <B><FONT COLOR="#228B22">struct</FONT></B> region{ <B><FONT COLOR="#228B22">int</FONT></B> color; <I><FONT COLOR="#B22222">// id of the color</FONT></I> <B><FONT COLOR="#228B22">int</FONT></B> area; <I><FONT COLOR="#B22222">// occupied area in pixels</FONT></I> <B><FONT COLOR="#228B22">int</FONT></B> x1,y1,x2,y2; <I><FONT COLOR="#B22222">// bounding box (x1,y1) - (x2,y2)</FONT></I> <B><FONT COLOR="#228B22">float</FONT></B> cen_x,cen_y; <I><FONT COLOR="#B22222">// centroid</FONT></I> yuv average; <I><FONT COLOR="#B22222">// average color (if CMV_COLOR_AVERAGES enabled)</FONT></I> <B><FONT COLOR="#228B22">int</FONT></B> sum_x,sum_y,sum_z; <I><FONT COLOR="#B22222">// temporaries for centroid and avg color</FONT></I> <I><FONT COLOR="#B22222">// int area_check; // DEBUG ONLY</FONT></I> region *next; <I><FONT COLOR="#B22222">// next region in list</FONT></I> <I><FONT COLOR="#B22222">// int number; // DEBUG ONLY</FONT></I> }; <B><FONT COLOR="#228B22">struct</FONT></B> rle{ <B><FONT COLOR="#228B22">unsigned</FONT></B> color; <I><FONT COLOR="#B22222">// which color(s) this run represents</FONT></I> <B><FONT COLOR="#228B22">int</FONT></B> length; <I><FONT COLOR="#B22222">// the length of the run (in pixels)</FONT></I> <B><FONT COLOR="#228B22">int</FONT></B> parent; <I><FONT COLOR="#B22222">// run's parent in the connected components tree</FONT></I> }; <B><FONT COLOR="#228B22">struct</FONT></B> color_info{ rgb color; <I><FONT COLOR="#B22222">// example color (such as used in test output)</FONT></I> <B><FONT COLOR="#228B22">char</FONT></B> *name; <I><FONT COLOR="#B22222">// color's meaninful name (e.g. ball, goal)</FONT></I> <B><FONT COLOR="#228B22">double</FONT></B> merge; <I><FONT COLOR="#B22222">// merge density threshold</FONT></I> <B><FONT COLOR="#228B22">int</FONT></B> expected_num; <I><FONT COLOR="#B22222">// expected number of regions (used for merge)</FONT></I> <B><FONT COLOR="#228B22">int</FONT></B> y_low,y_high; <I><FONT COLOR="#B22222">// Y,U,V component thresholds</FONT></I> <B><FONT COLOR="#228B22">int</FONT></B> u_low,u_high; <B><FONT COLOR="#228B22">int</FONT></B> v_low,v_high; }; <B><FONT COLOR="#228B22">struct</FONT></B> point{ <B><FONT COLOR="#228B22">double</FONT></B> x,y; }; <B><FONT COLOR="#228B22">struct</FONT></B> line{ point a,b; }; <B><FONT COLOR="#228B22">struct</FONT></B> rectangle{ <B><FONT COLOR="#228B22">int</FONT></B> x,y,w,h; };<B><FONT COLOR="#5F9EA0">protected</FONT></B>: <B><FONT COLOR="#228B22">unsigned</FONT></B> y_class[CMV_COLOR_LEVELS]; <B><FONT COLOR="#228B22">unsigned</FONT></B> u_class[CMV_COLOR_LEVELS]; <B><FONT COLOR="#228B22">unsigned</FONT></B> v_class[CMV_COLOR_LEVELS]; region region_table[CMV_MAX_REGIONS]; region *region_list[CMV_MAX_COLORS]; <B><FONT COLOR="#228B22">int</FONT></B> region_count[CMV_MAX_COLORS]; rle rmap[CMV_MAX_RUNS]; color_info colors[CMV_MAX_COLORS]; <B><FONT COLOR="#228B22">int</FONT></B> width,height; <B><FONT COLOR="#228B22">unsigned</FONT></B> *map; <B><FONT COLOR="#228B22">unsigned</FONT></B> options;<B><FONT COLOR="#5F9EA0">protected</FONT></B>:<I><FONT COLOR="#B22222">// Private functions</FONT></I> <B><FONT COLOR="#228B22">void</FONT></B> classifyFrame(image_pixel * restrict img,<B><FONT COLOR="#228B22">unsigned</FONT></B> * restrict map); <B><FONT COLOR="#228B22">int</FONT></B> encodeRuns(rle * restrict out,<B><FONT COLOR="#228B22">unsigned</FONT></B> * restrict map); <B><FONT COLOR="#228B22">void</FONT></B> connectComponents(rle * restrict map,<B><FONT COLOR="#228B22">int</FONT></B> num); <B><FONT COLOR="#228B22">int</FONT></B> extractRegions(region * restrict reg,rle * restrict rmap,<B><FONT COLOR="#228B22">int</FONT></B> num); <B><FONT COLOR="#228B22">void</FONT></B> calcAverageColors(region * restrict reg,<B><FONT COLOR="#228B22">int</FONT></B> num_reg, image_pixel * restrict img, rle * restrict rmap,<B><FONT COLOR="#228B22">int</FONT></B> num_runs); <B><FONT COLOR="#228B22">int</FONT></B> separateRegions(region * restrict reg,<B><FONT COLOR="#228B22">int</FONT></B> num); region *sortRegionListByArea(region * restrict list,<B><FONT COLOR="#228B22">int</FONT><
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -