1 | initial version |
2 | No.2 Revision |
please give
cv::Mat_<std::complex<int>> mat;
a try.
using CP = std::complex<int>;
cv::Mat_<CP> mat(2, 2);
mat.at<CP>(0, 0) = CP(3, 5);
mat.at<CP>(0, 1) = CP(3, 6);
mat.at<CP>(1, 0) = CP(3, 7);
mat.at<CP>(1, 1) = CP(3, 8);
std::cout<<mat<<std::endl;
mat.at<CP>(0, 0) = std::conj(mat.at<CP>(0, 0));
std::cout<<mat<<std::endl;
//Make all of the mat become conjugate
OCV::for_each_channels<CP>(mat, [](CP &a)
{
a = std::conj(a);
} );
std::cout<<mat<<std::endl;
implementation of for each
/**
*@brief apply stl like for_each algorithm on a channel
*
* @param T : the type of the channel(ex, uchar, float, double and so on)
* @param func : Unary function that accepts an element in the range as argument
*
*@return :
* return func
*/
template<typename T, typename UnaryFunc, typename Mat>
inline UnaryFunc for_each_channels(Mat &&input, UnaryFunc func)
{
int rows = input.rows;
int cols = input.cols;
if(input.isContinuous()){
cols = input.total() * input.channels();
rows = 1;
}
for(int row = 0; row != rows; ++row){
auto input_ptr = input.template ptr<T>(row);
for(int col = 0; col != cols; ++col){
func(input_ptr[col]);
}
}
return func;
}
for_each_channels<CP>([](CP &a)
{
a = cv::conj(a);
} );
3 | No.3 Revision |
please give
cv::Mat_<std::complex<int>> mat;
a try.
using CP = std::complex<int>;
cv::Mat_<CP> mat(2, 2);
mat.at<CP>(0, 0) = CP(3, 5);
mat.at<CP>(0, 1) = CP(3, 6);
mat.at<CP>(1, 0) = CP(3, 7);
mat.at<CP>(1, 1) = CP(3, 8);
std::cout<<mat<<std::endl;
mat.at<CP>(0, 0) = std::conj(mat.at<CP>(0, 0));
std::cout<<mat<<std::endl;
//Make all of the mat become conjugate
OCV::for_each_channels<CP>(mat, [](CP &a)
{
a = std::conj(a);
} );
std::cout<<mat<<std::endl;
implementation of for each
/**
*@brief apply stl like for_each algorithm on a channel
*
* @param T : the type of the channel(ex, uchar, float, double and so on)
* @param func : Unary function that accepts an element in the range as argument
*
*@return :
* return func
*/
template<typename T, typename UnaryFunc, typename Mat>
inline UnaryFunc for_each_channels(Mat &&input, UnaryFunc func)
{
int rows = input.rows;
int cols = input.cols;
if(input.isContinuous()){
cols = input.total() * input.channels();
rows = 1;
}
for(int row = 0; row != rows; ++row){
auto input_ptr = input.template ptr<T>(row);
for(int col = 0; col != cols; ++col){
func(input_ptr[col]);
}
}
return func;
}
for_each_channels<CP>([](CP &a)
{
a = cv::conj(a);
} );
4 | No.4 Revision |
please give
cv::Mat_<std::complex<int>> mat;
a try.
using CP = std::complex<int>;
cv::Mat_<CP> mat(2, 2);
mat.at<CP>(0, 0) = CP(3, 5);
mat.at<CP>(0, 1) = CP(3, 6);
mat.at<CP>(1, 0) = CP(3, 7);
mat.at<CP>(1, 1) = CP(3, 8);
std::cout<<mat<<std::endl;
mat.at<CP>(0, 0) = std::conj(mat.at<CP>(0, 0));
std::cout<<mat<<std::endl;
//Make all of the mat become conjugate
OCV::for_each_channels<CP>(mat, [](CP &a)
{
a = std::conj(a);
} );
std::cout<<mat<<std::endl;
implementation of for each
/**
*@brief apply stl like for_each algorithm on a channel
*
* @param T : the type of the channel(ex, uchar, float, double and so on)
* @param func : Unary function that accepts an element in the range as argument
*
*@return :
* return func
*/
template<typename T, typename UnaryFunc, typename Mat>
inline UnaryFunc for_each_channels(Mat &&input, UnaryFunc func)
{
int rows = input.rows;
int cols = input.cols;
if(input.isContinuous()){
cols = input.total() * input.channels();
rows = 1;
}
for(int row = 0; row != rows; ++row){
auto input_ptr = input.template ptr<T>(row);
for(int col = 0; col != cols; ++col){
func(input_ptr[col]);
}
}
return func;
}
std::complex support many operations, you could use the generic for_each loop to implement your codes
template<typename T>
inline void conj_mat(cv::Mat_<std::complex<T>> &mat)
{
for_each_channels<std::complex<T>>(mat, [](std::complex<T> &a){ a = std::conj(a); });
}
If you need more speed, take a look on this post.
5 | No.5 Revision |
please give
cv::Mat_<std::complex<int>> mat;
a try.
using CP = std::complex<int>;
cv::Mat_<CP> mat(2, 2);
mat.at<CP>(0, 0) = CP(3, 5);
mat.at<CP>(0, 1) = CP(3, 6);
mat.at<CP>(1, 0) = CP(3, 7);
mat.at<CP>(1, 1) = CP(3, 8);
std::cout<<mat<<std::endl;
mat.at<CP>(0, 0) = std::conj(mat.at<CP>(0, 0));
std::cout<<mat<<std::endl;
//Make all of the mat become conjugate
OCV::for_each_channels<CP>(mat, [](CP &a)
{
a = std::conj(a);
} );
std::cout<<mat<<std::endl;
implementation of for each
/**
*@brief apply stl like for_each algorithm on a channel
*
* @param T : the type of the channel(ex, uchar, float, double and so on)
* @param func : Unary function that accepts an element in the range as argument
*
*@return :
* return func
*/
template<typename T, typename UnaryFunc, typename Mat>
inline UnaryFunc for_each_channels(Mat &&input, UnaryFunc func)
{
int rows = input.rows;
int cols = input.cols;
if(input.isContinuous()){
cols = input.total() * input.channels();
rows = 1;
}
for(int row = 0; row != rows; ++row){
auto input_ptr = input.template ptr<T>(row);
for(int col = 0; col != cols; ++col){
func(input_ptr[col]);
}
}
return func;
}
std::complex support many operations, you could use the generic for_each loop to implement your codes
template<typename T>
inline void conj_mat(cv::Mat_<std::complex<T>> &mat)
{
for_each_channels<std::complex<T>>(mat, [](std::complex<T> &a){ a = std::conj(a); });
}
If you need more speed, take a look on this post.
6 | No.6 Revision |
please give
cv::Mat_<std::complex<int>> mat;
a try.
using CP = std::complex<int>;
cv::Mat_<CP> mat(2, 2);
mat.at<CP>(0, 0) = CP(3, 5);
mat.at<CP>(0, 1) = CP(3, 6);
mat.at<CP>(1, 0) = CP(3, 7);
mat.at<CP>(1, 1) = CP(3, 8);
std::cout<<mat<<std::endl;
mat.at<CP>(0, 0) = std::conj(mat.at<CP>(0, 0));
std::cout<<mat<<std::endl;
//Make all of the mat become conjugate
OCV::for_each_channels<CP>(mat, [](CP &a)
{
a = std::conj(a);
} );
std::cout<<mat<<std::endl;
implementation of for each
/**
*@brief apply stl like for_each algorithm on a channel
*
* @param T : the type of the channel(ex, uchar, float, double and so on)
* @param func : Unary function that accepts an element in the range as argument
*
*@return :
* return func
*/
template<typename T, typename UnaryFunc, typename Mat>
UnaryFunc for_each_channels(Mat &&input, UnaryFunc func)
{
{
int rows = input.rows;
int cols = input.cols;
if(input.isContinuous()){
cols = input.total() * input.channels();
rows = 1;
}
for(int row = 0; row != rows; ++row){
auto input_ptr begin = input.template ptr<T>(row);
for(int col = 0; col auto end = begin + cols;
while(begin != cols; ++col){
func(input_ptr[col]);
end){
func(*begin);
++begin;
}
}
return func;
}
std::complex support many operations, you could use the generic for_each loop to implement your codes
template<typename T>
inline void conj_mat(cv::Mat_<std::complex<T>> &mat)
{
for_each_channels<std::complex<T>>(mat, [](std::complex<T> &a){ a = std::conj(a); });
}
If you need more speed, take a look on this post.