这是我的代码:
printf("preallocations\n");
char * addr = (char *) bo_gc320->m_fb_id[gc320_buf_idx];
cv::Mat src(cvSize(bo_gc320->m_width, bo_gc320->m_height), CV_8UC4, addr);
cv::Mat alpha(cvSize(bo_gc320->m_width, bo_gc320->m_height), CV_8UC1);
cv::Mat rgb(cvSize(bo_gc320->m_width, bo_gc320->m_height), CV_8UC3);
cv::Mat dst(cvSize(bo_gc320->m_width, bo_gc320->m_height), CV_8UC3);
printf("postallocations\n");
cv::Mat * out = new cv::Mat[4];// malloc(4*sizeof(cv::Mat *));
for (int k=0;k<4;k++) {
out[k] = cv::Mat(cvSize(bo_gc320->m_width, bo_gc320->m_height), CV_8UC1);
printInfo(out[k]);
}
printf("presplit\n");
printInfo(src);
cv::split(src, out);
printf("postsplit\n");
并且输出为:
preallocations
postallocations
dim(332, 768)unsigned char(1)
dim(332, 768)unsigned char(1)
dim(332, 768)unsigned char(1)
dim(332, 768)unsigned char(1)
presplit
dim(332, 768)unsigned char(4)
Segmentation fault (core dumped)
我正在使用辅助函数打印有关阵列的信息。 addr中的数据来自gc320 GPU的输出缓冲区。这可能是由于addr不包含有效数据引起的吗?
证明addr实际上是无效数据,并且没有填充整个CV_8UC4 Mat结构。一旦更改了缓冲区,问题就解决了。