JoeHowse / iOSWithOpenCV

These are the projects for my book, iOS Application Development with OpenCV 3.
https://www.packtpub.com/application-development/ios-application-development-opencv
54 stars 18 forks source link

cv::xphoto::autowbGrayworld doesn't exists in opencv contrib version #3

Closed andrefrank closed 7 years ago

andrefrank commented 7 years ago

Hi had an issue with the tutorial 'CoolPig' from the first chapter. As described in your book I installed the opencv + contrib from Github and built the complete iOS framework. Obviously the xphoto.hpp doesn't contain the function 'autowbGrayworld. The function is used in the viewDidLoad method of the ViewController and Xcode always complain about.

However, this ugly peace of code worked for me: -(void) viewDidLoad .......

ifdef WITH_OPENCV_CONTRIB

        cv::xphoto::createGrayworldWB()->balanceWhite(originalMat, originalMat);

endif

..........

Kind regards

JoeHowse commented 7 years ago

Thanks for the report! The white balance API in opencv_contrib changed on August 9, 2016. I have now pushed an update to CoolPig/ViewController.m so that it uses the following code for the cases where the image is in color and white balance should be applied:

    case CV_8UC4: {
      // The cv::Mat is in RGBA format.
      // Convert it to RGB format.
      cv::cvtColor(originalMat, originalMat, cv::COLOR_RGBA2RGB);
#ifdef WITH_OPENCV_CONTRIB
      // Adjust the white balance.
      cv::Ptr<cv::xphoto::GrayworldWB> whiteBalancer = cv::xphoto::createGrayworldWB();
      whiteBalancer->balanceWhite(originalMat, originalMat);
#endif
      break;
    }
    case CV_8UC3: {
      // The cv::Mat is in RGB format.
#ifdef WITH_OPENCV_CONTRIB
      // Adjust the white balance.
      cv::Ptr<cv::xphoto::GrayworldWB> whiteBalancer = cv::xphoto::createGrayworldWB();
      whiteBalancer->balanceWhite(originalMat, originalMat);
#endif
      break;
    }