⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cont.c

📁 contvc.rar
💻 C
字号:
/*******************************************************************/
/*

Demo-Software for smart cameras from Vision Components
------------------------------------------------------

Program: Klaus Schneider,  VC


Program Description:
--------------------

After you start the program you get a overlay rectangle on the 
monitor. Put a black object inside this rectangle (white background)
and press a key. You get the contour, the start point and the
contour length (clockwise and counter-clockwise) as a 
result. You can see the contour on the monitor. Is the 
object is closed inside the rectangle, the contour length
of both direction has the same length. 

Example:

Contour Code for BLACK objects (Quite='q')

Press key to start
Start Point x0=165 y0=84
Result of the         clockwise contour8() = 01 length=355
Result of the counter-clockwise contour8() = 01 length=355

Press key to start
No black object found


*/
/*******************************************************************/

#include <vcrt.h>
#include <vclib.h>
#include <macros.h>
#include <sysvar.h>

/*******************************************************************/

#define cdisp_dx(a, src, col)    cdisp(a, src, col, (void (*)())WPIX);
WPIX(int x, int *adr) {wpix(x,adr);}

/*******************************************************************/

void main(void)

  {
  int   posx= 100, posy=100, dx=300, dy=300; /* search area */
  long  length=5000; /* maximum of the contour length */
  int   threshold=125; /* threshold */

  int   lx, x0=0, y0=0;
  int   res1=0,res2=0, *rlc, *input, i;
  long  dest1,dest2,desttemp, addr;
  char  c;
  image Area, Ovl;

  /* Working on Image 1 */
  ScrSetLogPage((int)ScrGetPhysPage);
  OvlSetLogPage((int)OvlGetPhysPage);

  /* clear overlay */
  OvlClearAll;

  /* Overlay on */
  set_ovlmask(255);

  /* define image variable (image) */
  ImageAssign(&Area,ScrByteAddr(posx,posy), dx, dy, ScrGetPitch);  

  /* define image variable (overlay) */
  ImageAssign(&Ovl,OvlBitAddr(posx,posy), dx, dy, OvlGetPitch);  

  /* Draw a rectangle */
  frameo(&Ovl);
  vmode(vmOvlLive);  

  /* follow contour */
  dest1=DRAMWordMalloc((long)length);
  dest2=DRAMWordMalloc((long)length);
 
  /* allocate memory for one line */
  rlc   = vcmalloc(ScrGetColumns);
  input = vcmalloc(ScrGetColumns);

  print("Contour Code for BLACK objects (Quite='q')\n");


  do
    {
    print("\nPress key to start\n"); c=rs232rcv();
    tpict();

    /* for higher processor power (better for progressive camera is vmode(vmOvlFreeze) ) */
    vmode(vmOvlLive);  

    /* delete old drawings, if exist */
    if (res1>0) cdisp_dx(&Ovl,dest1,0);
    if (res2>0) cdisp_dx(&Ovl,dest2,0);

    /* Get a possible start point: */
    /* - searching direction in this program is from left to right (= direction 2, please */
    /*   have a look at coutour code (VCLIB, page 8) */
    /* - start points are always black */
    /* - start points in this program have a white left neighbore (coming from direction 2) */
    /* - start points shouldn't be on the border of the search area; */
    /*   there must be the possibility to look for all neighbors of the pixel */

    /* Searching for a start point with the function rlcf() */
    addr = Area.st/2L+1L; /* not on the border of the searching area */
    lx   = dx - 4; 
    for (i=2;i<dy;i++)
      {
      addr += ScrGetPitch/2;
      blrdb(lx/2, input, addr);
      rlcmkf(lx, threshold, input, rlc);
      /* find the first change of color */
      if(*(rlc+1)<lx) 
        {
        /* select a black point as a start point */
        if (*rlc==-1) x0=*(rlc+1)+2;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
        else          x0=*(rlc+1)+1;
        y0=i-1;
        print("Start Point x0=%d y0=%d\n",x0,y0);
        break;
        }
      }

    /* find contour code in both directon (clockwise and counter-clockwise) */
    if (i==dy) 
      {
      print("No black object found\n");
      }
    else       
      {
      /* clockwise: the variable 'dir' from the function contour8 has to be the direction from where you come */
      /* possible is ~0,~1,~2,~3,~4,~5,~6,~7 (please have a look at coutour code (VCLIB, page 8) */
      desttemp = dest1;
      res1 = contour8(&Area,x0,y0,~2,threshold,length,&desttemp);
      print("Result of the         clockwise contour8() = %2d length=%ld\n",res1,rd32(dest1));
      if (res1>0) cdisp_dx(&Ovl,dest1,255);

      /* counter-clockwise: the variable 'dir' (function contour8) has to be the direction from where you come from */
      /* possible is 0,1,2,3,4,5,6,7 (please have a look at coutour code (VCLIB, page 8) */
      desttemp = dest2;
      res2 = contour8(&Area,x0,y0,2,threshold,length,&desttemp);
      print("Result of the counter-clockwise contour8() = %2d length=%ld\n",res2,rd32(dest2));
      if (res2>0) cdisp_dx(&Ovl,dest2,255);
      }
    }
  while(c!='q'); 


  /* have to be in the other way around than allocation (FILO) */
  DRAMWordFree(dest2);
  DRAMWordFree(dest1);

  /* free memory */
  vcfree(input);
  vcfree(rlc);
  }

/*******************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -