title: Why is webcam image processing slow while using Xcode in an OpenCV project?
body: <p>Why is webcam image processing is very slow while using Xcode for this OpenCV project, and only one out of three windows are working (similar spaces and HSV windows are not turning up) and are very slow? How to increase the speed of execution of the program?</p>
  
  <pre><code>#include &lt;opencv2/highgui/highgui.hpp&gt;
  #include &lt;opencv2/imgproc/imgproc.hpp&gt;
  #include &lt;iostream&gt;
  
  using namespace cv;
  using namespace std;
  
  Mat img, hsv, res;
  char *win1 = "RGB";
  char *win2 = "HSV";
  char *win3 = "similar spaces";
  uchar thresh = 5;
  
  void setColor(uchar hval){
      int i,j;
      for (i = 0; i &lt; res.rows; ++i){
          for (j = 0; j &lt; res.cols; ++j){
              if( hsv.at&lt;Vec3b&gt;(i,j)[0] &lt;= hval+thresh
              &amp;&amp;  hsv.at&lt;Vec3b&gt;(i,j)[0] &gt;= hval-thresh)
                  res.at&lt;uchar&gt;(i,j) = 255;
              else res.at&lt;uchar&gt;(i,j) = 0;
          }
      }
      imshow(win3, res);
  }
  
  void MouseCallBackFunc(int event, int x, int y, int flags, void* userdata){
  
      if(event==EVENT_LBUTTONDOWN){
          cout&lt;&lt;"\t x,y : "&lt;&lt;x&lt;&lt;','&lt;&lt;y&lt;&lt;endl;
          cout&lt;&lt;'\t'&lt;&lt;img.at&lt;Vec3b&gt;(y,x)&lt;&lt;endl;
          setColor(hsv.at&lt;Vec3b&gt;(y,x)[0]);
      }
  }
  
  int main()
  {
  
      img = imread("/usr/share/opencv/samples/cpp/stuff.jpg", CV_LOAD_IMAGE_COLOR);
      hsv = Mat::zeros(img.size(), CV_8UC3);
      res = Mat::zeros(img.size(), CV_8UC1);
      char c;
      int i,j;
      namedWindow(win2, CV_WINDOW_NORMAL);
      namedWindow(win3, CV_WINDOW_NORMAL);
  
      cvtColor(img, hsv, CV_RGB2HSV);
  
      imshow(win1, img);
      imshow(win2, hsv);
      imshow(win3, res);
      setMouseCallback(win1, MouseCallBackFunc, NULL);
  
  
      // VideoCapture stream(0);   //0 is the id of video device.0 if you have only one camera.
  
      // if (!stream.isOpened()) { //check if video device has been initialised
      //  cout &lt;&lt; "cannot open camera";
      // }
  
      // while (true) {
      //  Mat cameraFrame;
      //  stream.read(cameraFrame);
      //  imshow("test", cameraFrame);
      //  c = waitKey(30);
      //  if(c==27)
      //      break;
      // }
      while((c=waitKey(300))!=27){}
      return 0;
  } 
  </code></pre>