Advertisement
dan-masek

https://stackoverflow.com/questions/76999557/opencv-format-equivalent-to-gstreamer-gray16-be?noredir

Aug 29th, 2023
1,368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. #include <opencv2/opencv.hpp>
  2.  
  3. int main(int argc, char* argv[])
  4. {
  5.     uint32_t input[8] = {
  6.         0x01020304, 0x05060708
  7.         , 0x11121314, 0x15161718
  8.         , 0x21222324, 0x25262728
  9.         , 0x31323334, 0x35363738
  10.     };
  11.  
  12.     { // 16-bit byteswap
  13.         // View the input array as pairs of bytes...
  14.         cv::Mat byte_view(4, 4, CV_8UC2, input);
  15.         std::cout << byte_view << "\n";
  16.  
  17.         // Destination array
  18.         cv::Mat result = cv::Mat::zeros(4, 4, CV_16UC1);
  19.         // Temporary view of the data owned by result compatible with byte_view
  20.         cv::Mat out_view(4, 4, CV_8UC2, result.data);
  21.         int ch[] = { 1, 0, 0, 1 };
  22.         cv::mixChannels(&byte_view, 1, &out_view, 1, ch, 2);
  23.  
  24.         std::cout << out_view << "\n";
  25.         std::cout << result << "\n";
  26.     }
  27.  
  28.     { // 32-bit byteswap
  29.         // View the input array as 4-tuples of bytes...
  30.         cv::Mat byte_view(4, 2, CV_8UC4, input);
  31.         std::cout << byte_view << "\n";
  32.  
  33.         cv::Mat result = cv::Mat::zeros(4, 4, CV_16UC1);
  34.         // Temporary view of the data owned by result compatible with byte_view
  35.         cv::Mat out_view(4, 2, CV_8UC4, result.data);
  36.         int ch[] = { 0, 3, 1, 2, 2, 1, 3, 0 };
  37.         cv::mixChannels(&byte_view, 1, &out_view, 1, ch, 4);
  38.  
  39.         std::cout << out_view << "\n";
  40.         std::cout << result << "\n";
  41.     }
  42.  
  43.     return 0;
  44. }
  45.  
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement