Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void splitTo3Channel_dan1(const cv::Mat& input, std::vector<cv::Mat>& output)
- {
- CV_Assert(!input.empty());
- CV_Assert(input.channels() == 3);
- // (re)allocate outputs
- output.clear();
- for (int i(0); i < input.channels(); ++i) {
- output.push_back(cv::Mat::zeros(input.size(), input.type()));
- }
- // Set up index pairs (input->output);
- int from_to[] = { 0,0, 1,4, 2,8 };
- cv::mixChannels(&input, 1, &output[0], 3, from_to, 3);
- }
- void splitTo3Channel_dan1b(const cv::Mat& input, std::vector<cv::Mat>& output)
- {
- CV_Assert(!input.empty());
- CV_Assert(input.channels() == 3);
- // (re)allocate outputs
- output.clear();
- for (int i(0); i < input.channels(); ++i) {
- output.push_back(cv::Mat::zeros(input.size(), input.type()));
- }
- // Set up index pairs (input->output);
- std::vector<int> from_to{ 0,0, 1,4, 2,8 };
- CV_Assert(from_to.size() == (output.size() * 2));
- cv::mixChannels(&input, 1
- , &output[0], output.size()
- , &from_to[0], output.size());
- }
- void splitTo3Channel_dan1c(const cv::Mat& input, std::vector<cv::Mat>& output)
- {
- CV_Assert(!input.empty());
- // (re)allocate outputs
- output.clear();
- for (int i(0); i < input.channels(); ++i) {
- output.push_back(cv::Mat::zeros(input.size(), input.type()));
- }
- // Set up channel index pairs (input->output);
- std::vector<int> from_to;
- for (int i(0); i < input.channels(); ++i) {
- from_to.push_back(i); // Input
- from_to.push_back(i * input.channels() + i); // Output
- }
- cv::mixChannels(&input, 1
- , &output[0], output.size()
- , &from_to[0], output.size());
- }
- void splitToNChannel_dan2(const cv::Mat& input
- , std::vector<cv::Mat>& output
- , bool reuse_output = false)
- {
- CV_Assert(!input.empty());
- CV_Assert(input.channels() <= 4); // Not tested for more than 4
- CV_Assert(output.empty() || (output.size() == input.channels()));
- // Allocate (or just clear if reusing/possible to reuse) outputs
- if (reuse_output && (output.size() == input.channels())) {
- for (int i(0); i < input.channels(); ++i) {
- if ((output[i].size() == input.size()) && (output[i].type() == input.type())) {
- output[i].setTo(cv::Scalar());
- } else {
- output[i] = cv::Mat::zeros(input.size(), input.type());
- }
- }
- } else {
- output.clear();
- for (int i(0); i < input.channels(); ++i) {
- output.push_back(cv::Mat::zeros(input.size(), input.type()));
- }
- }
- // Set up channel index pairs (input->output);
- std::vector<int> from_to;
- for (int i(0); i < input.channels(); ++i) {
- from_to.push_back(i); // Input
- from_to.push_back(i * input.channels() + i); // Output
- }
- cv::mixChannels(&input, 1
- , &output[0], output.size()
- , &from_to[0], output.size());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement