OPENCV Mat Multi-Channel C + + operation method (for Windows/linux)

Source: Internet
Author: User
Tags scalar

Recently in doing OPENCV multi-channel operation found on-line examples are very few, in order to facilitate the memory of their own write a demo.

Example in VS2010 + OpenCV 2.4.9 compiled through, as long as the configuration of the OpenCV Lib path can be run.

This method is suitable for C + + operations under Windows/linux, both Windows and Ubuntu have tried.

#include <opencv2/opencv.hpp> #include <iostream> #pragma comment (lib, "Opencv_core249d.lib") using Namespace Std;using namespace Cv;void testchannels () {filestorage fs;string file = "Channel_methods.xml"; Fs.open (file, Filestorage::write), if (!fs.isopened ()) {Cerr << "error:could not open '" << file << Endl;} vec2f need to correspond to the number of channels defined by the matrix and data type CV_32FC2, if the 4-channel float type should be defined as vec4f//the first usage of Mat code (1, ten, CV_32FC2, Scalar::all (0)); mat_<vec2f> _code = code; for (int k = 0; k < k++) {_code (0, k) [0]++; _code (0, k) [1]=1;} Code = _CODE;FS << "method_1st" << code;//The second usage of the Mat code_2 (1, ten, CV_32FC2, Scalar::all (0)); for (int k = 0; K & Lt 10; k++) {code_2.at<vec2f> (0, k) [0]++; code_2.at<vec2f> (0, k) [1]=2;} FS << "method_2nd" << code_2;//third usage vector<mat> split_code;split (code, Split_code); for (int k = 0; K &lt ; 10; k++) {split_code[0].at<float> (0, K) + +; split_code[1].at<float> (0, k) = 3;} Mat Merge_code (1, CV_32FC2, Scalar:: All (0)), merge (Split_code, Merge_code), FS << "method_3rd" << merge_code;//release resources such as Code.release ();}int Main (int argc, char** argv) {testchannels ();}


OPENCV Mat Multi-Channel C + + operation method (for Windows/linux)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.