Bad argument (Unknown array type) in cvarrToMat [closed]
Could anyone advise on the following error ?
Verbose terminal output
phung@UbuntuHW15:~/Documents/fpga_overlay/xillybus-eval-xl-virtex7-2.0b_DATE/verilog/vivado/xillydemo.srcs/sources_1/imports/taylor$ gcc -g host.c -o host `pkg-config --cflags --libs opencv`
phung@UbuntuHW15:~/Documents/fpga_overlay/xillybus-eval-xl-virtex7-2.0b_DATE/verilog/vivado/xillydemo.srcs/sources_1/imports/taylor$ ./host
OpenCV Error: Bad argument (Unknown array type) in cvarrToMat, file /build/opencv-SviWsf/opencv-2.4.9.1+dfsg/modules/core/src/matrix.cpp, line 698
terminate called after throwing an instance of 'cv::Exception'
what(): /build/opencv-SviWsf/opencv-2.4.9.1+dfsg/modules/core/src/matrix.cpp:698: error: (-5) Unknown array type in function cvarrToMat
Aborted (core dumped)
phung@UbuntuHW15:~/Documents/fpga_overlay/xillybus-eval-xl-virtex7-2.0b_DATE/verilog/vivado/xillydemo.srcs/sources_1/imports/taylor$ read() failed: Input/output error
host.c
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdint.h>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#define N 512
struct packet{
uint8_t r,g,b;
};
int main(int argc, char *argv[]) {
int fdr, fdw, rc, donebytes;
char *buf;
pid_t pid;
struct packet *tologic, *fromlogic;
int i;
float a, da;
fdr = open("/dev/stdin", O_RDONLY);
fdw = open("/dev/stdout", O_WRONLY);
if ((fdr < 0) || (fdw < 0)) {
perror("Failed to open Xillybus device file(s)");
exit(1);
}
pid = fork();
if (pid < 0) {
perror("Failed to fork()");
exit(1);
}
if (pid) {
close(fdr);
tologic = malloc(sizeof(struct packet) * N * N); // lena.tiff is sized as 512*512*3
if (!tologic) {
fprintf(stderr, "Fa
iled to allocate memory\n");
exit(1);
}
CvArr* src = cvLoadImageM("lena512color.tiff", CV_LOAD_IMAGE_COLOR); //load image
CvArr *r, *g, *b; //destination array
// https://docs.opencv.org/2.4/modules/core/doc/operations_on_arrays.html#split
cvSplit(src, r, g, b, (CvArr *)NULL); // split source into its respective [r, g, b] components
//Note: OpenCV uses BGR color order
//https://docs.opencv.org/2.4.13.6/modules/core/doc/old_basic_structures.html?highlight=cvarr#get-d
cvGet1D(b, tologic[i].b); // blue channel
cvGet1D(g, tologic[i].g); // green channel
cvGet1D(r, tologic[i].r); // red channel
buf = (char *) tologic;
donebytes = 0;
while (donebytes < sizeof(struct packet) * N) {
rc = write(fdw, buf + donebytes, sizeof(struct packet) * N - donebytes);
if ((rc < 0) && (errno == EINTR))
continue;
if (rc <= 0) {
perror("write() failed");
exit(1);
}
donebytes += rc;
}
sleep(1); // Let debug output drain (if used)
close(fdw);
return 0;
}
else {
close(fdw);
fromlogic = malloc(sizeof(struct packet) * N);
if (!fromlogic) {
fprintf(stderr, "Failed to allocate memory\n");
exit(1);
}
buf = (char *) fromlogic;
donebytes = 0;
while (donebytes < sizeof(struct packet) * N) {
rc = read(fdr, buf + donebytes, sizeof(struct packet) * N - donebytes);
if ((rc < 0) && (errno == EINTR))
continue;
if (rc < 0) {
perror("read() failed");
exit(1);
}
if (rc == 0) {
fprintf(stderr, "Reached read EOF!? Should never happen.\n");
exit(0);
}
donebytes += rc;
}
// for (i=0; i<N; i++)
printf("R:%d ...
Closed for the following reason
question is not relevant or outdated by
berak
close date 2018-04-23 11:07:04.303005
Comments
- please AVOID using opencv's deprecated c-api, it is no more maintained, and there is no more support for it. please use c++ (cv::Mat) or python, if you' re so inclined.
- also, most of opencv is NOT threadsafe ! and your fork() will get you in to unnessecary trouble.
berak (
2018-04-23 11:06:47 -0600
)edit
add a comment