Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Use type to specify operation rather than using enum

In openCV2, enum always use to specify what kind of operation we want to perform like

cv::threshold(input, output, 128, 255, cv::THRESH_BINARY);
cv::threshold(input, output, 128, 255, cv::THRESH_BINARY_INV);
.....
cv::threshold(input, output, 128, 255, cv::THRESH_TOZERO);

Is it possible to provide the api like

cv::threshold(input, output, 128, 255, cv::THR_BINARY);
cv::threshold(input, output, 128, 255, cv::THR_BINARY_INV);
.....
cv::threshold(input, output, 128, 255, cv::THR_TOZERO);

cv::THR_BINARY, cv::THR_BINARY_INV, cv::THR_TOZERO are empty classes This way, we could find out the type is valid or not and determine which operation should take at compile time

Would this kind of api violate the coding standard of openCV?

Use type to specify operation rather than using enum

In openCV2, enum always use to specify what kind of operation we want to perform like

cv::threshold(input, output, 128, 255, cv::THRESH_BINARY);
cv::threshold(input, output, 128, 255, cv::THRESH_BINARY_INV);
.....
cv::threshold(input, output, 128, 255, cv::THRESH_TOZERO);

Is it possible to provide the api like

cv::threshold(input, output, 128, 255, cv::THR_BINARY);
cv::threshold(input, output, 128, 255, cv::THR_BINARY_INV);
.....
cv::threshold(input, output, 128, 255, cv::THR_TOZERO);

cv::THR_BINARY, cv::THR_BINARY_INV, cv::THR_TOZERO are empty classes classes. This way, we could find out the type is valid or not and determine which operation should take at compile time

Would this kind of api violate the coding standard of openCV?

click to hide/show revision 3
retagged

updated 2013-09-19 05:10:17 -0600

berak gravatar image

Use type to specify operation rather than using enum

In openCV2, enum always use to specify what kind of operation we want to perform like

cv::threshold(input, output, 128, 255, cv::THRESH_BINARY);
cv::threshold(input, output, 128, 255, cv::THRESH_BINARY_INV);
.....
cv::threshold(input, output, 128, 255, cv::THRESH_TOZERO);

Is it possible to provide the api like

cv::threshold(input, output, 128, 255, cv::THR_BINARY);
cv::threshold(input, output, 128, 255, cv::THR_BINARY_INV);
.....
cv::threshold(input, output, 128, 255, cv::THR_TOZERO);

cv::THR_BINARY, cv::THR_BINARY_INV, cv::THR_TOZERO are empty classes. This way, we could find out the type is valid or not and determine which operation should take at compile time

Would this kind of api violate the coding standard of openCV?

Use type to specify operation rather than using enum

In openCV2, enum always use to specify what kind of operation we want to perform like

cv::threshold(input, output, 128, 255, cv::THRESH_BINARY);
cv::threshold(input, output, 128, 255, cv::THRESH_BINARY_INV);
.....
cv::threshold(input, output, 128, 255, cv::THRESH_TOZERO);

Is it possible to provide the api like

cv::threshold(input, output, 128, 255, cv::THR_BINARY);
cv::threshold(input, output, 128, 255, cv::THR_BINARY_INV);
.....
cv::threshold(input, output, 128, 255, cv::THR_TOZERO);

cv::THR_BINARY, cv::THR_BINARY_INV, cv::THR_TOZERO are empty classes. This way, we could find out the type is valid or not and determine which operation should take at compile time

Would this kind of api violate the coding standard of openCV?

Edit : @berak, no problem.I would paste the pseudo codes at here

class BGR2RGB{}; 
class BGR2GRAY{};
BGR2GRAY CV_BGR2GRAY;
BGR2RGB CV_BGR2RGB;
....//and so on

//declaration of cv::cvtColor
cv::cvtColor(cv::Mat &input, cv::Mat &output, cv::BGR2RGB method);
cv::cvtColor(cv::Mat &input, cv::Mat &output, cv::BGR2GRAY method);

//call it like this way
cv::cvtColor(cv::Mat &input, cv::Mat &output, CV_BGR2GRAY);
cv::cvtColor(cv::Mat &input, cv::Mat &output, CV_BGR2RGB);
//oops, compile time error since there are nothing like CV_BGR2RGBAA    
cv::cvtColor(cv::Mat &input, cv::Mat &output, CV_BGR2RGBAA);

other example class BINARY_THRESH{}; //.....

cv::threshold(cv::Mat &input, cv::Mat &output, double thresh, double maxValue, 
cv::BINARY_THRESH method, bool otsu = false);

//the flag otsu could use type to replace too, but without the use of template, the codes //would become very verbose(openCV do not encourage the use of template?)

The idea are come from the source codes of stl, use type and overload to do compile time if..else, this is faster because the choice are made at compile time, and safer since the compiler would complain when you provide invalid type.You could check about the implementation of std::copy.With the keywords of constexpr, the results could be better, but openCV do not accept c++11 yet.

Use type to specify operation rather than using enum

In openCV2, enum always use to specify what kind of operation we want to perform like

cv::threshold(input, output, 128, 255, cv::THRESH_BINARY);
cv::threshold(input, output, 128, 255, cv::THRESH_BINARY_INV);
.....
cv::threshold(input, output, 128, 255, cv::THRESH_TOZERO);

Is it possible to provide the api like

cv::threshold(input, output, 128, 255, cv::THR_BINARY);
cv::threshold(input, output, 128, 255, cv::THR_BINARY_INV);
.....
cv::threshold(input, output, 128, 255, cv::THR_TOZERO);

cv::THR_BINARY, cv::THR_BINARY_INV, cv::THR_TOZERO are empty classes. This way, we could find out the type is valid or not and determine which operation should take at compile time

Would this kind of api violate the coding standard of openCV?

Edit : @berak, no problem.I would paste the pseudo codes at here

class BGR2RGB{}; 
class BGR2GRAY{};
BGR2GRAY CV_BGR2GRAY;
BGR2RGB CV_BGR2RGB;
....//and so on

//declaration of cv::cvtColor
cv::cvtColor(cv::Mat &input, cv::Mat &output, cv::BGR2RGB method);
cv::cvtColor(cv::Mat &input, cv::Mat &output, cv::BGR2GRAY method);

//call it like this way
cv::cvtColor(cv::Mat &input, cv::Mat &output, CV_BGR2GRAY);
cv::cvtColor(cv::Mat &input, cv::Mat &output, CV_BGR2RGB);
//oops, compile time error since there are nothing like CV_BGR2RGBAA    
cv::cvtColor(cv::Mat &input, cv::Mat &output, CV_BGR2RGBAA);

other example class BINARY_THRESH{}; //.....

cv::threshold(cv::Mat &input, cv::Mat &output, double thresh, double maxValue, 
cv::BINARY_THRESH method, bool otsu = false);

//the flag otsu could use type to replace too, but without the use of template, the codes //would become very verbose(openCV do not encourage the use of template?)

The idea are come from the source codes of stl, use type and overload to do compile time if..else, this is faster because the choice are made at compile time, and safer since the compiler would complain when you provide invalid type.You could check about the implementation of std::copy.With the keywords of constexpr, the results could be better, better(maybe), but openCV do not accept c++11 yet.

Use type to specify operation rather than using enum

In openCV2, enum always use to specify what kind of operation we want to perform like

cv::threshold(input, output, 128, 255, cv::THRESH_BINARY);
cv::threshold(input, output, 128, 255, cv::THRESH_BINARY_INV);
.....
cv::threshold(input, output, 128, 255, cv::THRESH_TOZERO);

Is it possible to provide the api like

cv::threshold(input, output, 128, 255, cv::THR_BINARY);
cv::threshold(input, output, 128, 255, cv::THR_BINARY_INV);
.....
cv::threshold(input, output, 128, 255, cv::THR_TOZERO);

cv::THR_BINARY, cv::THR_BINARY_INV, cv::THR_TOZERO are empty classes. This way, we could find out the type is valid or not and determine which operation should take at compile time

Would this kind of api violate the coding standard of openCV?

Edit : @berak, no problem.I would paste the pseudo codes at here

class BGR2RGB{}; 
class BGR2GRAY{};
BGR2GRAY CV_BGR2GRAY;
BGR2RGB CV_BGR2RGB;
....//and so on

//declaration of cv::cvtColor
cv::cvtColor(cv::Mat &input, cv::Mat &output, cv::BGR2RGB method);
cv::cvtColor(cv::Mat &input, cv::Mat &output, cv::BGR2GRAY method);

//call it like this way
cv::cvtColor(cv::Mat &input, cv::Mat &output, CV_BGR2GRAY);
cv::cvtColor(cv::Mat &input, cv::Mat &output, CV_BGR2RGB);
//oops, compile time error since there are nothing like CV_BGR2RGBAA    
cv::cvtColor(cv::Mat &input, cv::Mat &output, CV_BGR2RGBAA);

other example class BINARY_THRESH{}; //.....

cv::threshold(cv::Mat &input, cv::Mat &output, double thresh, double maxValue, 
cv::BINARY_THRESH method, bool otsu = false);

//the flag otsu could use type to replace too, but without the use of template, the codes //would become very verbose(openCV do not encourage the use of template?)too

The idea are come from the source codes of stl, use type and overload to do compile time if..else, this is faster because the choice are made at compile time, and safer since the compiler would complain when you provide invalid type.You could check about the implementation of std::copy.With the keywords of constexpr, the results could be better(maybe), but openCV do not accept c++11 yet.

Use type to specify operation rather than using enum

In openCV2, enum always use to specify what kind of operation we want to perform like

cv::threshold(input, output, 128, 255, cv::THRESH_BINARY);
cv::threshold(input, output, 128, 255, cv::THRESH_BINARY_INV);
.....
cv::threshold(input, output, 128, 255, cv::THRESH_TOZERO);

Is it possible to provide the api like

cv::threshold(input, output, 128, 255, cv::THR_BINARY);
cv::threshold(input, output, 128, 255, cv::THR_BINARY_INV);
.....
cv::threshold(input, output, 128, 255, cv::THR_TOZERO);

cv::THR_BINARY, cv::THR_BINARY_INV, cv::THR_TOZERO are empty classes. This way, we could find out the type is valid or not and determine which operation should take at compile time

Would this kind of api violate the coding standard of openCV?

Edit : @berak, no problem.I would paste the pseudo codes at here

class BGR2RGB{}; 
class BGR2GRAY{};
BGR2GRAY CV_BGR2GRAY;
BGR2RGB CV_BGR2RGB;
....//and so on

//declaration of cv::cvtColor
cv::cvtColor(cv::Mat &input, cv::Mat &output, cv::BGR2RGB method);
cv::cvtColor(cv::Mat &input, cv::Mat &output, cv::BGR2GRAY method);

//call it like this way
cv::cvtColor(cv::Mat &input, cv::Mat &output, CV_BGR2GRAY);
cv::cvtColor(cv::Mat &input, cv::Mat &output, CV_BGR2RGB);
//oops, compile time error since there are nothing like CV_BGR2RGBAA    
cv::cvtColor(cv::Mat &input, cv::Mat &output, CV_BGR2RGBAA);

other example example

class BINARY_THRESH{};
    //.....

//.....

cv::threshold(cv::Mat &input, cv::Mat &output, double thresh, double maxValue, 
cv::BINARY_THRESH method, bool otsu = false);

//the flag otsu could use type to replace too

The idea are come from the source codes of stl, use type and overload to do compile time if..else, this is faster because the choice are made at compile time, and safer since the compiler would complain when you provide invalid type.You could check about the implementation of std::copy.With the keywords of constexpr, the results could be better(maybe), but openCV do not accept c++11 yet.

Use type to specify operation rather than using enum

In openCV2, enum always use to specify what kind of operation we want to perform like

cv::threshold(input, output, 128, 255, cv::THRESH_BINARY);
cv::threshold(input, output, 128, 255, cv::THRESH_BINARY_INV);
.....
cv::threshold(input, output, 128, 255, cv::THRESH_TOZERO);

Is it possible to provide the api like

cv::threshold(input, output, 128, 255, cv::THR_BINARY);
cv::threshold(input, output, 128, 255, cv::THR_BINARY_INV);
.....
cv::threshold(input, output, 128, 255, cv::THR_TOZERO);

cv::THR_BINARY, cv::THR_BINARY_INV, cv::THR_TOZERO are empty classes. This way, we could find out the type is valid or not and determine which operation should take at compile time

Would this kind of api violate the coding standard of openCV?

Edit : @berak, no problem.I would paste the pseudo codes at here

class BGR2RGB{}; 
class BGR2GRAY{};
BGR2GRAY CV_BGR2GRAY;
BGR2RGB CV_BGR2RGB;
....//and so on

//declaration of cv::cvtColor
cv::cvtColor(cv::Mat &input, cv::Mat &output, cv::BGR2RGB method);
cv::cvtColor(cv::Mat &input, cv::Mat &output, cv::BGR2GRAY method);

//call it like this way
cv::cvtColor(cv::Mat &input, cv::Mat &output, CV_BGR2GRAY);
cv::cvtColor(cv::Mat &input, cv::Mat &output, CV_BGR2RGB);
//oops, compile time error since there are nothing like CV_BGR2RGBAA    
cv::cvtColor(cv::Mat &input, cv::Mat &output, CV_BGR2RGBAA);

other example

class BINARY_THRESH{};
//.....

cv::threshold(cv::Mat &input, cv::Mat &output, double thresh, double maxValue, 
cv::BINARY_THRESH method, bool otsu = false);

//the flag otsu flag(otsu) could use type to replace too

The idea are come from the source codes of stl, use type and overload to do compile time if..else, this is faster because the choice are made at compile time, and safer since the compiler would complain when you provide invalid type.You could check about the implementation of std::copy.With the keywords of constexpr, the results could be better(maybe), but openCV do not accept c++11 yet.