Code Generation, Image processing, Blank Output

Question: We have a prototype image processing project in Matlab and want to "port" it to Jetson TX1. The "imgaborfilt" works differently than the OpenCV gabor filter, so I want to generate only "imgaborfilt" into c++ so that we can have the same result. Is this possible? To get the Matlab implementation into C++, without having to digg/research and implement it myself.
Effort level: I've spent 30+ hours reading documentation and countless blog posts / forum
Goal: Use Matlab coder to generate C++ files(Tried dynamic DLL, static lib and source code) from Very Simple Matlab Functions and use them in conjunction with OpenCV functions and Mat containers.
Problem: I tried generating edge('Sobel'), rgb2gray and imgaborfilt. When I use the generated function the image always comes out Blank (Only black pixels) as If the function does nothing.
Setup: Visual studio 2015, Matlab 2017a, OpenCV3.2. All verified and working.
Very Simple Matlab Functions to be generated example:
if true
% code
function BW = Only_Sobel(I,tresh) %#codegen
method = 'Sobel';
direction = 'vertical';
BW = edge(I, method, tresh, direction);
end
The exerciser script:
if true
% code
I = imread('Pall.png');
I = im2double(I);
Gray = rgb2gray(I);
tresh = 1;
BW = manual_sobel(Gray,tresh);
figure
imshow(BW);
end
Visual code:
if true
% code
static unsigned char uv0[88350];
static boolean_T BW[88350];
Mat image;
VideoCapture cap;
cap.open(0);
namedWindow("Large Window", 1);
namedWindow("HorzEdgeDetect", 1);
namedWindow("final_result",1);
//Mat pall(155,570,DataType<uchar>::type);
int size[2] = { 570, 155 };
// Mat test(3, size, DataType<uchar>::type);
Mat pall;
pall = imread("Pall.png", 1);
// The pall.png image is 155x570 pixels
int width = 570;
int height = 155;
cvtColor(pall, pall, COLOR_BGR2GRAY);
//Generated function for image container
argInit_155x570_uint8_T(uv0);
argInit_155x570_uint8_T(BW);
//Transfer the image to the generated image container used by the generated code
int ii, jj;
for (ii = 0; ii < width; ii++)
for (jj = 0; jj < height; jj++)
uv0[ii * height + jj] = (real_T)(pall.data[ii + width * jj]);
imshow("HorzEdgeDetect", pall);
//DEBUG, send the data back into "Mat pall" och verify
for (ii = 0; ii < width; ii++)
for (jj = 0; jj < height; jj++)
pall.data[ii + width * jj] = (uchar)uv0[ii * height + jj];
imshow("Large Window", pall);
//double tresh = 55;
double tresh = 0.015;
Only_Sobel(uv0, tresh, BW);
Mat image_sobel;
image_sobel = pall;
//Get the data into MAT container for display
for (ii = 0; ii < width; ii++)
for (jj = 0; jj < height; jj++)
image_sobel.data[ii + width * jj] = (uchar)BW[ii * height + jj];
//Display results
imshow("final_result", image_sobel);
while (1) {
cap >> image; //copy webcam stream to image
// imshow("Large Window", image); //print image to screen
waitKey(33); //delay 33ms
}
end

Answers (0)

Categories

Asked:

on 17 Apr 2017

Edited:

on 18 Apr 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!