Ask Your Question

jordanthompson's profile - activity

2015-08-10 09:51:37 -0600 commented question Problems capturing image from LI-USB30-V024STEREO Leopard Imaging stereo board

I have uploaded the images and verified that this last set is correct. I really appreciate your help with this.

2015-08-09 06:56:11 -0600 received badge  Enthusiast
2015-08-05 04:17:49 -0600 received badge  Editor (source)
2015-08-04 23:40:01 -0600 asked a question Problems capturing image from LI-USB30-V024STEREO Leopard Imaging stereo board

Hi there, I have a LI-USB30-V024STEREO board which interlaces the grayscale image into a single image. I am reading the images from the two cameras and displaying it into several windows, including the original image, but am unable to properly grab the gray-scale video from the source.

I have gotten some information and code from Leopard Imaging, but I think there is still a disconnect. They have provided to me what they are telling me is required to extract the two images from a frame. I have included the code below as well as before and after images of a frame. I am calling their code from ImageProcessing::process(). Any help you may provide would be most appreciated.

Raw, original image:

Processed Image:

#include "ImageProcessor.h"
#include "../handlers/menu/Menu.h"
#include "../utils/WindowUtils.h"

#include <vector>
#include <iostream>
#include <opencv2/highgui/highgui.hpp>
#include <stdio.h>
#include <SDL/SDL.h>

using namespace cv;
using namespace std;

string ImageProcessor::theWindowName = "Video";

ImageProcessor::ImageProcessor()
: videoCapture(0), myScreen(0), myFrameNumber(0) {
  isRunningX = WindowUtils::isRunningX();

  if (!videoCapture.isOpened()) {
    cout << "Cannot open the video cam" << endl;
  }

  if (isRunningX) {
    namedWindow(theWindowName.c_str(), CV_WINDOW_FULLSCREEN);
    cvNamedWindow(theWindowName.c_str(), CV_WINDOW_NORMAL);
    cvSetWindowProperty(theWindowName.c_str(), CV_WND_PROP_FULLSCREEN, CV_WINDOW_FULLSCREEN);
  } else {
    SDL_Init(SDL_INIT_EVERYTHING);
    SDL_ShowCursor(0);
  }
}

#define BYTE uchar
#define WORD ushort
#define TRUE 1
#define FALSE 0
static unsigned short linear_to_gamma[65536];
static double gammaValue = -1;
static int gBPP = 0;
void bayer_to_rgb24(uint8_t *pBay, uint8_t *pRGB24, int width, int height, int pix_order);
int raw_to_bmp_mono(BYTE* in_bytes, BYTE* out_bytes, int width, int height, int bpp,
        bool GammaEna, double gamma);

bool ImageProcessor::process(Mat& matOut) {
// Leopard Imaging
unsigned char* ptr = (unsigned char*) malloc(myMat.cols * myMat.rows * 3);
unsigned char* ptr2 = (unsigned char*) malloc(myMat.cols * myMat.rows * 3);
bayer_to_rgb24(myMat.data, ptr, myMat.cols, myMat.rows, 1);
raw_to_bmp_mono(ptr, ptr2, myMat.cols, myMat.rows, 8, true, 1.6);
  int i = 0;

  for (int row = 0; row < matOut.rows; row++) {
    for (int col = 0; col < matOut.cols; col++) {
      Vec3b colorVect;
      colorVect.val[0] = ptr2[i];
      colorVect.val[1] = ptr2[i];
      colorVect.val[2] = ptr2[i];
      matOut.at<Vec3b>(Point(col, row)) = colorVect;
      i+=2;
    }
  }
  if (myFrameNumber == 10) {
    writePngImage("/tmp/image.png", matOut, false);
    writeInfo("/tmp/image.csv", matOut, false);
    cout << "image snapped" << endl;
  }
  myFrameNumber++;
  free(ptr);
  free(ptr2);
}

void ImageProcessor::writePngImage(const string & fileName,
        const Mat& mat, bool isColor) {
  vector<int> compression_params;
  compression_params.push_back(IMWRITE_PNG_COMPRESSION);

  if (isColor) {
    compression_params.push_back(9);
  } else {
    compression_params.push_back(3);
  }

  try {
    imwrite(fileName, mat, compression_params);
  } catch (...) {
    fprintf(stderr, "Exception converting image to PNG format\n");
  }
}

void ImageProcessor::writeInfo(const std::string & fileName,
        const Mat& mat, bool isColor) {
  FILE* file = fopen(fileName.c_str(), "w");
  uchar* ptr = mat.data;
  // write the header row
  for (int col = 0; col < mat.cols; col++) {
    if (isColor) {
      fprintf(file, "%3d[0]\t%3d[1]\t%3d[2]", col, col, col);
    } else {
      fprintf(file, "%3d[0]\t%3d[1]", col, col);
    }
    if (col < mat.cols - 1) {
      fprintf(file, "\t");
    }
  }
  fprintf(file, "\n");

  int val = 2;
  switch (val) {
    case 1:
      // write the data using the class
      for (int row ...
(more)