Announcement

Collapse
No announcement yet.

My code doesn't get updated

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • My code doesn't get updated

    I'm coding with vs code c++, have pi with frc image watching mjpeg feed on frcvision.local:1182
    On this port I can see my processed image with circles drawn around any circle like shapes in my orange masked image, till this point all is good.

    Now I've decided to draw circles on original mat, to see a circle around the ball(cargo) in the raw image. So I changed this line:
    mOrigSource.PutFrame(mask);
    to this
    mOrigSource.PutFrame(mat);
    in MyVisionPipeline.h file that I've created in wpi folder.
    which should display raw image, but for some reason the executable remains the same, I mean some changes I can make but the camera feed remains the same no matter what!
    I open win shell and type make and the file multiCameraServerExample is rebuilt I then upload it to server and re run feed, which remains the same..!!

    Please advise.
    Thanks.





  • #2
    It's hard to debug without seeing more of your code. It sounds like you're successfully uploading the code (you can confirm this by adding a couple of prints and seeing if they show up in the console), so the problem is more likely somewhere in the OpenCV processing.

    Comment


    • #3
      class MyPipelines : public frc::VisionPipeline {
      public:
      int val =0;
      clock_t start;
      double duration;
      std::shared_ptr<NetworkTable> table;
      //NetworkTable *table;

      cs::CvSource mOrigSource;
      MyPipelines()
      {
      wpi:: puts() <<"starting stream2\n";
      mOrigSource = frc::CameraServer::GetInstance()->PutVideo("stream2", 256, 144);
      /* Your algorithm here */
      start = clock();
      NetworkTable::SetClientMode();
      table = NetworkTable::GetTable("datatable");
      }
      void Process(cv::Mat& mat) override {
      //Anwar's code starts here:
      wpi puts() <<"Vision processing started..."<<mat.size().height<<"x"<<mat.size().wi dth<<"\n";
      duration = ( clock() - start ) / (double) CLOCKS_PER_SEC;
      cv::Mat tempMat = mat;//(mat);// create copy of original image to use for ball detection
      cv::Scalar orangeHsvMin = (0,100,50);//(5, 50, 50);
      cv::Scalar orangeHsvMax = (0,100,100);//(15, 255, 255);
      // Convert from BGR to HSV colorspace
      cv::Mat hsvMat=mat;
      cv::Mat thresholded=mat;
      //cv::GaussianBlur(hsvMat, thresholded,cv::Size(3,3),0);
      cv::Mat img=mat;//(mat);
      cv::GaussianBlur(img,img,cv::Size(1,1),0);
      cv::cvtColor(img,img,cv::COLOR_BGR2HSV);
      for(int y=0;y<img.rows;y++)
      {
      for(int x=0;x<img.cols;x++)// inRange alternative.
      {
      // get pixel
      cv::Vec3b color = img.at<cv::Vec3b>(cv::Point(x,y));
      // ... do something to the color ....
      if(color[0]>=3&& color[0]<=25&& color[1]>=100&& color[1]<=255&& color[2]>=100&& color[2]<=255)
      color = {100,255,255};
      else
      {
      color = {0,0,0};
      }

      // set pixel
      img.at<cv::Vec3b>(cv::Point(x,y)) = color;
      }
      }
      HelperFunctionsAnwar helpFunction;
      mat = helpFunction.DetectCirclesAndDrawThem(img, &mat);//use tempMat for detection and draw on mat
      tempMat.deallocate();
      thresholded.deallocate();
      table->PutNumber("X",10);
      table->PutNumber("Y",2);
      //Anwar's code ends here.
      mOrigSource.PutFrame(mat); // <-- here only changed to mat
      }
      };



      class HelperFunctionsAnwar
      {
      private:
      /* data */
      public:
      //HelperFunctionsAnwar(/* args */);
      //~HelperFunctionsAnwar();

      HelperFunctionsAnwar(/* args */)
      {
      }
      ~HelperFunctionsAnwar()
      {
      }


      cv::Mat DetectCirclesAndDrawThem(cv::Mat src, cv::Mat *origin){// this takes in HSV image after inRange
      cv::Mat tempMat(src);
      //cv::cvtColor(src, src, CV_HSV2BGR);
      cv::cvtColor(src, tempMat, CV_BGR2GRAY); //CV_HSV2RGB
      ///src.convertTo(tempMat, CV_8U, 1 / 256.0);
      cv::GaussianBlur(tempMat, tempMat, cv::Size(7, 7), 0); //Blur Effect
      //cv::dilate(tempMat, tempMat, 1); // Dilate Filter Effect
      cv::erode(tempMat, tempMat, 1); // Erode Filter Effect
      std::vector<cv::Vec3f> v3fCircles;

      cv::HoughCircles(tempMat,v3fCircles,CV_HOUGH_GRADI ENT,
      2,tempMat.rows /4,200,80,10,150); // algorithm for detecting circles

      for (int i =0; i < v3fCircles.size(); i++) { // for each circle

      wpi uts() <<"Ball position X = "<< v3fCircles[i][0] // x position of center point of circle // deleted :: from code webpage turns it to smily!!
      <<",\tY = "<< v3fCircles[i][1] // y position of center point of circle
      <<",\tRadius = "<< v3fCircles[i][2]<<"\n"; // radius of circle
      // draw small green circle at center of object detected
      cv::circle(*origin, // draw on original image
      cv::Point((int)v3fCircles[i][0], (int)v3fCircles[i][1]), // center point of circle
      3, // radius of circle in pixels
      cv::Scalar(255, 255, 255), // draw white
      CV_FILLED); // thickness
      // draw red circle around object detected
      cv::circle(*origin, // draw on original image
      cv::Point((int)v3fCircles[i][0], (int)v3fCircles[i][1]), // center point of circle
      (int)v3fCircles[i][2], // radius of circle in pixels
      cv::Scalar(255, 255, 255), // draw white
      2); // thickness
      }
      return tempMat;
      }
      };
      Last edited by anwarsaiah; 02-15-2019, 01:01 AM.

      Comment


      • #4
        What are you expecting to see on the stream? The code above draws circles on mat (you pass it into the DetectCirclesAndDrawThem function, which draws circles on it). Note that the assignment operator (e.g. cv::Mat tempMat = mat) does NOT make a copy of the Mat. It just creates another reference to the SAME Mat. You have to use the clone() function to create a deep copy (e.g. cv::Mat tempMat = mat.clone())

        Comment


        • #5
          Thanks, You are a life saver. I've tried both cv::Mat tempMat = mat; and cv::Mat tempMat(mat); but it never occurred to me to use cv::Mat tempMat = mat.clone(); although I've been familiar with it from other projects! This solved the issue.

          Comment

          Working...
          X