473,320 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

error "identifier not found" for MIN & MAX .beginner with a advanced program

.
Expand|Select|Wrap|Line Numbers
  1. #define MIN(a,b) (a<b?a:b)
  2.  
  3. #define MAX(a,b) (a>b?a:b)
  4.  
  5. #include "Video.h"
  6.  
  7. #define NO_HUE -1
  8.  
  9. // CS added.
  10.  
  11. #include <math.h>
  12.  
  13. #include <fstream>
  14.  
  15. #include <iostream>
  16.  
  17. #include "stdafx.h"
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27. int Video :: RGBtoHue(int r, int g, int b)
  28.  
  29. {
  30.  
  31.   int hue, delta, max, min;
  32.  
  33.  
  34.  
  35.   max   = MAX(r, MAX(g,b));
  36.  
  37.   min   = MIN(r, MIN(g,b));
  38.  
  39.   delta = max - min;
  40.  
  41.   hue =0;
  42.  
  43.  
  44.  
  45. //----------------------------------------------------------------------------------------------------------
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.   /* initialise hue*/
  54.  
  55.   if (2 * delta <= max) {hue = NO_HUE;}
  56.  
  57.   else {
  58.  
  59.     if (r == max) hue =  42 + 42*(g-b) / delta; /* 1*42 */
  60.  
  61.     else if  (g == max) hue = 126 + 42*(b-r) / delta; /* 3*42 */
  62.  
  63.     else if (b == max) hue = 210 + 42*(r-g) / delta; /* 5*42 */
  64.  
  65.     /* now: hue is in range [0..252] */
  66.  
  67.   }
  68.  
  69.  
  70.  
  71.   return hue;
  72.  
  73. }
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81. //-------------------------------------------------------------------------------------------------------------
  82.  
  83.  Video::Video(int x, int y, int width, int height) : Fl_Window(x, y, width *2, height*2, "RA_LAB5 iVideoCap"){
  84.  
  85.      setUpDone = false;
  86.  
  87.  
  88.  
  89.  
  90.  
  91.      display = new Fl_Box(x,y,width,height); // Raw Image Display
  92.  
  93.  
  94.  
  95.  
  96.  
  97.      this->add(display);
  98.  
  99.  
  100.  
  101.      this->end();
  102.  
  103.      this->show();
  104.  
  105.  
  106.  
  107.      Fl::add_timeout(1.0, callback, this);
  108.  
  109.  };
  110.  
  111.  
  112.  
  113. // Video Deconstructor
  114.  
  115. Video::~Video(){
  116.  
  117.      VI.stopDevice(0);
  118.  
  119.  
  120.  
  121.  
  122.  
  123.      if (setUpDone) {delete [] pic;}
  124.  
  125. };
  126.  
  127. // Setup Cammera 
  128.  
  129. void Video::setUpCam(){
  130.  
  131.      if(!setUpDone){
  132.  
  133.       VI.setupDevice(0,640,480);
  134.  
  135.       this->resize(this->x(),this->y(),VI.getWidth(0),VI.getHeight(0));
  136.  
  137.  
  138.  
  139.       pic =  new uchar[3*VI.getWidth(0)*VI.getHeight(0)];
  140.  
  141.       display->resize(0,0,VI.getWidth(0),VI.getHeight(0));
  142.  
  143.  
  144.  
  145.       rgbImg = new Fl_RGB_Image(pic,VI.getWidth(0),VI.getHeight(0));
  146.  
  147.  
  148.  
  149.       display->image(rgbImg);
  150.  
  151.  
  152.  
  153.       setUpDone = true;
  154.  
  155.       bb=0 ; 
  156.  
  157.       for(int i=0 ;  i <16 ; i++ )
  158.  
  159.           medi[i]=0;
  160.  
  161.       }
  162.  
  163.  
  164.  
  165.      }
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173. //--------------------------------------------------------------------------------------------------------------------
  174.  
  175. void Video::goahead(){
  176.  
  177.     int modo;
  178.  
  179.     int i;
  180.  
  181.     int j;
  182.  
  183.     int limit;
  184.  
  185. int huecalc,max,maxi,rows,columns;
  186.  
  187.     //typedef uchar colimage[640][480][3];
  188.  
  189.     //colimage j_newPic;
  190.  
  191.     max=0;
  192.  
  193.     //int count[640];
  194.  
  195. //....
  196.  
  197.     if(camConnected()){
  198.  
  199.  
  200.  
  201.         this->setUpCam();
  202.  
  203.  
  204.  
  205.      if( VI.isFrameNew(0)){
  206.  
  207.  
  208.  
  209.  
  210.  
  211.     modo = VI.getWidth(0) *3 ;
  212.  
  213. int r,g,b;
  214.  
  215.           uchar *newPic  = grabFrame();
  216.  
  217.          //j_newPic = const_cast<uchar* >(pic);
  218.  
  219.          //*j_newPic  = grabFrame();// + VI.getWidth(0)*VI.getHeight(0)*3 ;
  220.  
  221.           /*uchar *newPicc*/m_newPicc = const_cast<uchar* >(pic);
  222.  
  223.          //j_newPic = const_cast<uchar* >(pic);
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233. int  average = 0 ;  // to keep the average of the picture 
  234.  
  235. int histo[641];     //    horisontal histogram 
  236.  
  237. int vertical_histo[481];  // vertical histogram
  238.  
  239. int vh=481;  // used to trace the vertical histogram 
  240.  
  241.  
  242.  
  243. for(i=0;i<640;i++)
  244.  
  245. histo[i]=0;
  246.  
  247. for(i=0;i<481;i++)
  248.  
  249. vertical_histo[i]=0; 
  250.  
  251.  
  252.  
  253.     int x;     //  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.     int y =1 ; //  temporary , only for check  , every one frame one hueToscreen
  260.  
  261.     int heuToscreen = 0 ;   // is used to show the output of the heucalc function
  262.  
  263.     int intensity = 0         ;
  264.  
  265.  
  266.  
  267.  
  268.  
  269. //------------------------------------------------------------------------------------------------------------
  270.  
  271.  
  272.  
  273.             for( i = VI.getWidth(0)*(VI.getHeight(0)-1)*3; i >= 0; i-=modo){
  274.  
  275.                  limit =  i+ modo;
  276.  
  277.                  x = 0 ; //
  278.  
  279.                  vh--; //  [ 480 -> 0 ]
  280.  
  281.  
  282.  
  283.             for (j = i; j <limit;) {
  284.  
  285.  
  286.  
  287.                  m_newPicc[j++] = *(newPic++);
  288.  
  289.                  r=(int)m_newPicc[j];
  290.  
  291.                  m_newPicc[j++] = *(newPic++);
  292.  
  293.                  g=(int)m_newPicc[j];
  294.  
  295.                  m_newPicc[j++] = *(newPic++);
  296.  
  297.                  b=(int)m_newPicc[j];
  298.  
  299.  
  300.  
  301.                  huecalc = RGBtoHue(b,r,g);
  302.  
  303.                  intensity = (r+g+b)/3 ; 
  304.  
  305.  
  306.  
  307.  
  308.  
  309. //------------------------   code to specify the heucalc -------------------
  310.  
  311.  
  312.  
  313.                   // if(j%50==0 ){
  314.  
  315.                   // printf(" \n\n\n   hue : %d \n",huecalc);
  316.  
  317.                    //printf("    intensity is : %d ",intensity);
  318.  
  319.                   //  }
  320.  
  321.  
  322.  
  323.  
  324.  
  325.                       //if(y++%(2000)==0){
  326.  
  327.                       //cout <<huecalc<<"\n";y=0;}
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335. //---------------------------------------------------------------------------
  336.  
  337.  
  338.  
  339.                 x++;//   0 - 640   horizontal histogram index
  340.  
  341.                 //if(  48<=huecalc && huecalc<=53 && intensity < 150)         //labcam  red     noon      indoor   lab/evening      [43.. 45]
  342.  
  343.                 //if(  43<=huecalc && huecalc<=45 && intensity < 150)         //labcam  red     noon      outdoor   cloude/sun      [43.. 45]
  344.  
  345.                 //if(  73<=huecalc && huecalc<=76)// && intensity < 150)      //labcam  yellow  noon      outdoor   cloude/sun      [72.. 76]
  346.  
  347.                 //if(  68<=huecalc && huecalc<=73)// && intensity < 150)      //mycam   yellow  night     indoor                    [68.. 73] 
  348.  
  349.                 //if(  76<=huecalc && huecalc<=88)// && intensity < 150)      //mycam   yellow  noon      indoor    cloudy/sun/lamp [76.. 88] 
  350.  
  351.                 if(  84<=huecalc && huecalc<=87)// && intensity < 150)  // yellow/outdoor/dull [84:87]
  352.  
  353.                 {
  354.  
  355.  
  356.  
  357.                     histo[x]++;       // horizontal histo
  358.  
  359.  
  360.  
  361.                     //cout <<vh<<"\n";
  362.  
  363.  
  364.  
  365.                     vertical_histo[vh]++;      // vertical histo 
  366.  
  367.  
  368.  
  369.                  }
  370.  
  371.               } } 
  372.  
  373. //---------------------------------------------------------------------------------
  374.  
  375.  
  376.  
  377.          // left max of the horisontal histo
  378.  
  379.          int max1=-1;int centre=-1;
  380.  
  381.  
  382.  
  383.          for(i=0;i<641;i++) 
  384.  
  385.          if(histo[i]>max1) 
  386.  
  387.          {
  388.  
  389.          max1=histo[i];
  390.  
  391.          }
  392.  
  393.  
  394.  
  395.          for(i=0;i<641;i++)
  396.  
  397.          if(max1==histo[i])
  398.  
  399.          {centre=i;
  400.  
  401.           break;}
  402.  
  403.  
  404.  
  405.   // ------  left max of the vertical histo ----------------------------------------
  406.  
  407.          int max2=-1;
  408.  
  409.          int centre2=-1;
  410.  
  411.  
  412.  
  413.          for(i=0;i<481;i++) 
  414.  
  415.          if(vertical_histo[i]>max2) 
  416.  
  417.          {
  418.  
  419.          max2=vertical_histo[i];
  420.  
  421.          }
  422.  
  423.  
  424.  
  425.          for(i=0;i<481;i++)
  426.  
  427.          if(max2==vertical_histo[i])
  428.  
  429.          {centre2=i;
  430.  
  431.           break;}
  432.  
  433.  
  434.  
  435.  
  436.  
  437. //-----------------------------------------------------------------------------------
  438.  
  439. //  calculating the average of medians
  440.  
  441. if (bb<15)
  442.  
  443. {
  444.  
  445.         bb++;
  446.  
  447.         medi[bb]=centre;
  448.  
  449.  
  450.  
  451. }
  452.  
  453.  
  454.  
  455.  
  456.  
  457. if(bb==15)
  458.  
  459. {
  460.  
  461. //every 15 itteration  b   [1..15] pick the 5 meadianvalues , then average them 
  462.  
  463.         bb=0;
  464.  
  465.  
  466.  
  467.         for(i = 1;i<=15;i++)    // first sort the array
  468.  
  469.         for (j=i;j<=15;j++)
  470.  
  471.           if (medi[i]<medi[j])
  472.  
  473.             {mid=medi[i];
  474.  
  475.             medi[i]=medi[j];
  476.  
  477.             medi[j]=mid;}
  478.  
  479.             mid=0;
  480.  
  481.  
  482.  
  483.             for(i=7;i<=9;i++)
  484.  
  485.         mid+=medi[i];
  486.  
  487.         //printf("%d \n",mid);}
  488.  
  489. //cout << "\n\n\n the avgerage of 3 medeian number is   : " <<  ;
  490.  
  491.  
  492.  
  493.         int avg =mid/3; 
  494.  
  495.         //cout << "\n\n\n the avgerage of 3 medeian number is   : " << avg << "\n";
  496.  
  497.  
  498.  
  499.  
  500.  
  501. //ploting a vertical line in the center of the picture :
  502.  
  503.  
  504.  
  505.          if ( max1>6 ) 
  506.  
  507.          for( i = avg*3  ; i <=VI.getWidth(0)*(VI.getHeight(0)-1)*3  ; i+=modo)
  508.  
  509.          {
  510.  
  511.          m_newPicc[i] = 0; 
  512.  
  513.          m_newPicc[i+1] = 0;
  514.  
  515.          m_newPicc[i+2] = 0;
  516.  
  517.          }
  518.  
  519.  
  520.  
  521.          //cout << "\n centre2 is  : " <<centre2 ; 
  522.  
  523.  
  524.  
  525.  
  526.  
  527.          //cout << centre2 <<"\n";
  528.  
  529.          //ploting a vertical line in the center of the picture :
  530.  
  531.  
  532.  
  533.          if (centre2 != -1  &&  centre2 != 0 &&  max2>6) {
  534.  
  535.          for( i =(centre2-1)*(640*3) ; i <=(centre2)*(640*3) ; i++)
  536.  
  537.          {
  538.  
  539.          m_newPicc[i] = 0; 
  540.  
  541.          }
  542.  
  543.          for( i =(centre2)*(640*3) ; i <=(centre2+1)*(640*3) ; i++)
  544.  
  545.          {
  546.  
  547.          m_newPicc[i] = 0; 
  548.  
  549.          }}
  550.  
  551.  
  552.  
  553.          if(centre<200 && centre>0 && max1>6 && max2>6){angle=1;}
  554.  
  555.          if(centre>440 && centre<640 && max1>6 && max2>6){angle=2;}
  556.  
  557.          if(centre>200 && centre<440 && max1>6 && max2>6){angle=3;}
  558.  
  559.          if(centre==0 || max1<=6 || max2<=6){angle=0;}
  560.  
  561.  
  562.  
  563.  
  564.  
  565.  
  566.  
  567.  
  568.  
  569.  
  570.  
  571. }//  end of  : if(bb==15)
  572.  
  573.  
  574.  
  575.  
  576.  
  577.  
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587. //------------------------------------------------
  588.  
  589.   // ofstream out("documentation",ios::app) ;
  590.  
  591.   //        while(!out.is_open()){;}
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.  
  599.  
  600.  
  601. //if (centre < 10) cout << "NO OBJECT \n";
  602.  
  603. //if (260<centre<340) cout << "OBJECT IN THE MIDDLE \n";
  604.  
  605. //if ( centre<200) cout << "OBJECT IN THE LEFT \n";
  606.  
  607. //if (400<centre) cout << "OBJECT IN THE RIGHT \n";
  608.  
  609.  
  610.  
  611.  
  612.  
  613. //printf("%d , ",centre);     //  to read the center of the object   
  614.  
  615. //      out << "\t center of the object : " << centre ;
  616.  
  617. //    out.close();          
  618.  
  619.  
  620.  
  621.  
  622.  
  623.  
  624.  
  625. //printf("%d , ",heuToscreen); // is used to rea the correc heu
  626.  
  627. //cout << "\t\n average of the picture is  :"<<average ; 
  628.  
  629.  
  630.  
  631.  
  632.  
  633. //-----------------------------------------------------------------------------------------------
  634.  
  635. //int error=320-centre;
  636.  
  637. //angle=error/8;
  638.  
  639.  
  640.  
  641.  
  642.  
  643. //------------------------------------------------------------------------------------------------
  644.  
  645.         rgbImg->uncache();
  646.  
  647.  display->redraw();
  648.  
  649.  
  650.  
  651.         }
  652.  
  653.     }
  654.  
  655.     else{
  656.  
  657.         display->copy_label("NO CAMERA CONNECTED");
  658.  
  659.         setUpDone = false;
  660.  
  661.     }
  662.  
  663.  
  664.  
  665.  
  666.  
  667.  
  668.  
  669.         Fl::repeat_timeout(0.003, callback,this);
  670.  
  671.  
  672.  
  673.  
  674.  
  675.      };
  676.  
  677. //---------------------------------- END ----------------------------------------------------------
  678.  
Oct 13 '09 #1
6 6735
Banfa
9,065 Expert Mod 8TB
You have posted 600 lines of code (although there is an excessive quantity of blank lines) and an error but have not said what line the error is on.
Oct 13 '09 #2
sorry for the big code... plz look at the specific error posted below

Expand|Select|Wrap|Line Numbers
  1. #define int MIN(int a,int b) (a<b?a:b)
  2. #define int MAX(int a,int b) (a>b?a:b)
  3. #include "Video.h"
  4. #define NO_HUE -1
  5. // CS added.
  6. #include <math.h>
  7. #include <fstream>
  8. #include <iostream>
  9. #include "stdafx.h"
  10.  
  11.  
  12.  
  13.  
  14. int Video :: RGBtoHue(int r, int g, int b)
  15. {
  16.   int hue, delta, max, min;
  17.  
  18.   max   = int MAX(r, int MAX(g,b));
  19.   min   = int MIN(r, int MIN(g,b));
  20.   delta = max - min;
  21.   hue =0;
  22.  
  23. //----------------------------------------------------------------------------------------------------------
  24.  
  25.  
  26.  
  27.   /* initialise hue*/
  28.   if (2 * delta <= max) {hue = NO_HUE;}
  29.   else {
  30.     if (r == max) hue =  42 + 42*(g-b) / delta; /* 1*42 */
  31.     else if  (g == max) hue = 126 + 42*(b-r) / delta; /* 3*42 */
  32.     else if (b == max) hue = 210 + 42*(r-g) / delta; /* 5*42 */
  33.     /* now: hue is in range [0..252] */
  34.   }
  35.  
  36.   return hue;
  37. }
  38.  

The error is type 'int' unexpected in lines 18 and 19
Oct 13 '09 #3
Banfa
9,065 Expert Mod 8TB
The error means that the syntax checker unexpectedly encounter the word "int" in the code syntax.

In this case you do not need int before either MIN or MAX.
Oct 13 '09 #4
donbock
2,426 Expert 2GB
You are defining the MIN and MAX macros as if they were inline functions. I've heard a lot of C++ experts denounce macros. I suggest you go all the way and replace the #define's with inline function definitions.
Oct 13 '09 #5
Banfa
9,065 Expert Mod 8TB
Actually if you are going to do that why not just include <algorithm> and use the STL version of min/max.
Oct 13 '09 #6
hey guys thanks for the help.. ill make the recommended changes
Oct 14 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Kent | last post by:
Hi! I think i know whats the problem but not how to solve it. I have two classes, named A and B. The A class has a list<B*> And the B class has an pure virtual method declared as: void...
4
by: Stephen Corey | last post by:
I've got 2 classes in 2 seperate header files, but within the same namespace. If I use a line like: // This code is inside Class2's header file Class1 *newitem = new Class1(param1, param2); ...
2
by: Philipp Schumann | last post by:
Dear all, I'm in the process of designing a distributed application on the basis of ASP.NET, which does not contain of scripts, but of assemblies containing classes that implement IHttpHandler...
2
by: Marty Meyers | last post by:
I have the following line in a php file: $msg= exec("perl $scriptPath/insert.pl $d $u $t 2>&1", $returnVal); Can someone explain the "2>&1" argument? Second problem, this same line of code...
0
by: RCM | last post by:
I am really eager to quit the Microsoft world and get into LAMP. For the immediate future I can't do the Apache part, so I am at least trying to get PHP up and running under IIS to learn it. I...
0
by: ashluvcadbury | last post by:
Hi all I have visual studio 2003 and also configured IIS.But not able to execute any web application. I am a beginner and all the small web applications I had made some days days ago were...
1
by: mknoll217 | last post by:
I am recieving this error from my code: The multi-part identifier "PAR.UniqueID" could not be bound. The multi-part identifier "Salary.UniqueID" could not be bound. The multi-part identifier...
0
by: Blubaugh, David A. | last post by:
Sir, Thank you for your reply. This is as to how I developed my .pyd file. I entered the following commands within my MS-DOS prompt within Windows XP: C:\python25\ScriptsC:\python25\python ...
6
by: muby | last post by:
Hi everybody :) I'm modifying a C++ code in VC++ 2005 my code snippet void BandwidthAllocationScheduler::insert( Message* msg, BOOL* QueueIsFull,
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.