0

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 <time.h>
 #include <unistd.h>
 #include <opencv2/opencv.hpp>
 #include <stack>
 #include <limits.h>
 #include <time.h>
 #include <stdlib.h>
 #include <fcntl.h>
 #include <sys/mman.h>

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

 if (argc < 3) {
    printf("Usage: %s <phys_addr> <offset>\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

ZF007
  • 3,708
  • 8
  • 29
  • 48
Gagandeep
  • 11
  • 6
  • "but I am not getting proper Image frame" what's that supposed to mean. please be more specific. – Piglet Apr 05 '19 at 10:59
  • please refer my Question I added it inside my question – Gagandeep Apr 05 '19 at 11:22
  • Please don't post code that doesn't work and contains extraneous rubbish like `"o continue"` on the third line. Why are you showing a load of memory mapping code? How do the images get into the memory you are looking into? Why are you showing us the output image twice in your question - what's the difference? – Mark Setchell Apr 06 '19 at 16:49
  • I apologized for my couple of mistakes, I corrected them. I have raw image data in BGR format which stored in the read buffer, I tried with the above code but it is not working for me. please provide any solution for me. thanx you – Gagandeep Apr 08 '19 at 06:10
  • You still didn't answer why you are showing a load of memory mapping code nor how the data gets into the memory... – Mark Setchell Apr 08 '19 at 07:01

0 Answers0