Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <opencv2/opencv.hpp>
- int main(int argc, char* argv[])
- {
- uint32_t input[8] = {
- 0x01020304, 0x05060708
- , 0x11121314, 0x15161718
- , 0x21222324, 0x25262728
- , 0x31323334, 0x35363738
- };
- { // 16-bit byteswap
- // View the input array as pairs of bytes...
- cv::Mat byte_view(4, 4, CV_8UC2, input);
- std::cout << byte_view << "\n";
- // Destination array
- cv::Mat result = cv::Mat::zeros(4, 4, CV_16UC1);
- // Temporary view of the data owned by result compatible with byte_view
- cv::Mat out_view(4, 4, CV_8UC2, result.data);
- int ch[] = { 1, 0, 0, 1 };
- cv::mixChannels(&byte_view, 1, &out_view, 1, ch, 2);
- std::cout << out_view << "\n";
- std::cout << result << "\n";
- }
- { // 32-bit byteswap
- // View the input array as 4-tuples of bytes...
- cv::Mat byte_view(4, 2, CV_8UC4, input);
- std::cout << byte_view << "\n";
- cv::Mat result = cv::Mat::zeros(4, 4, CV_16UC1);
- // Temporary view of the data owned by result compatible with byte_view
- cv::Mat out_view(4, 2, CV_8UC4, result.data);
- int ch[] = { 0, 3, 1, 2, 2, 1, 3, 0 };
- cv::mixChannels(&byte_view, 1, &out_view, 1, ch, 4);
- std::cout << out_view << "\n";
- std::cout << result << "\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement