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 ...
For mat constructor it is row and col at line Mat matLow(matIn.cols, matIn.rows, CV_8UC1);
something is wrong here Mat matMid(matIn.rows, matIn.rows, CV_8UC1); May be you shoud write loop like this :
I don't understand. So let's try split plane:
I'm not sure. You can try
sorry i forget :
after imshow you have to insert line
In png image plane 0 and 2 are quite similar and plane 1 is an unknown for me. I cannot see any disparity due to stereo I have try to convert color space using this without success :
I have seen your post here. Can you debug this project using visual studio? May be opencv uses a wong driver for this camera
Can you send three images first with left blacking camera second with right camera blacking and third with all camera active pointing same scene?
first Image 14389661582674824.png second Image 14389661688312743.png plane 0and 2 all pixels are 255 plane 1 some pixels are ranging to 113 161 (button right) third 14389661805812268.png plan like previous image I cannot see disparity. plane 0and 2 all pixels are 255 and plan 1 is an halo. Using Leopardimaging software can you have image like third image?
If you send me good image I think opencv driver is false.
I have uploaded the images and verified that this last set is correct. I really appreciate your help with this.
I still think something is wrong. But we can try something. We have an unknown image with three plane X,Y and Z. We can suppose that a specific matriw such that [right Left ]'=M [X Y Z]'. symbol ' is for transpose. We have to identify M a 2 rows by three colum matrix. With saturated image is not a good way (not enough equation). A better way is to take first a stereo image of a scene, second only left image (with right image black) and third a right image (with left image black). After we have a linear system to solve...
Please can you clean your post it is difficult to find your new data (post is very large)