How to Read the BGR format RAW Image data from the Read buffer using opencv
06:27 05 Apr 2019

I have one Read buffer which has BGR 8 bit raw Image data, I want to read it by using opencv Mat function, I tried below code but I am not getting proper Image frame, It seems like my program not reading Read buffer properly

I tried this code

 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 

 using namespace std;
 using namespace cv;
 //using namespace std::chrono;
 int main(int argc , char *argv[]) {

 if (argc < 3) {
    printf("Usage: %s  \n", argv[0]);
    return 0;
 }

 off_t offset = strtoul(argv[1], NULL, 0);
 size_t len = strtoul(argv[2], NULL, 0);

 /* Truncate offset to a multiple of the page size, or mmap will fail. */
 size_t pagesize = sysconf(_SC_PAGE_SIZE);
 off_t page_base = (offset / pagesize) * pagesize;
 off_t page_offset = offset - page_base;

 int fd = open("/dev/mem", O_SYNC);

 unsigned char *mem = (unsigned char*)mmap(NULL, page_offset + len, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, page_base);
 if (mem == MAP_FAILED) {

    perror("Can't map memory");
    return -1;
 }

cout << &mem << endl; // print the virtual address of the memory buffer

cv::Mat dst;
while(1)
 {

    cv::Mat imgbuf(Size(640, 480), CV_8UC3, mem, 640*3);
   
            imshow("image2",imgbuf);

            waitKey(0);
            destroyAllWindows();
     }
        return 0;
}

output Image:

2

c++ opencv image-processing