导致LINUX版车辆视频检测器崩溃的原因:由于使用VPU取帧,帧图像有个高度不正常的现象,在代码 中有裁剪帧图像的操作,由于其中两个摄像头的宽、高颠倒了,比如:宽352 高288,结果成了宽288,高352了,在kernel->dataitem_image.cpp->lzf_saveImage()的部分代码中有裁剪帧图像的代码 ,由于裁剪尺寸超过帧图像的宽度,故引起了崩溃现象。改正确的代码如下,这样就可以容错了。
qDebug()<<"curframe is not null";
//此处代码主要解决VPU硬解码得到的图像的高度不正确的问题,强制修改为标准尺寸,裁掉多余的部分
//下面分别对不同尺寸的视频的宽和高都做了判断,原因是有些地方的摄像头的宽和高是反着的,比如:宽:352 高:288,
//但是有些摄像头却是反着的,所以要进行判断,否则,就会引起系统崩溃,因为裁剪的宽度超过实际帧的宽度就会引起崩溃
Mat tempimg;
if(curframe.size().width==1920){
cv::Rect rect(0, 0, 1920,1080);
curframe(rect).copyTo(tempimg);
}else if(curframe.size().width==1080){
cv::Rect rect(0, 0, 1080,1920);
curframe(rect).copyTo(tempimg);
}
else if(curframe.size().width==1280){
cv::Rect rect(0, 0, 1280,720);
curframe(rect).copyTo(tempimg);
}else if(curframe.size().width==720){
cv::Rect rect(0, 0, 720,1280);
curframe(rect).copyTo(tempimg);
}else if(curframe.size().width==704){
cv::Rect rect(0, 0, 704,576);
curframe(rect).copyTo(tempimg);
}else if(curframe.size().width==576){
cv::Rect rect(0, 0, 576,704);
curframe(rect).copyTo(tempimg);
}else if(curframe.size().width==640){
cv::Rect rect(0, 0, 640,480);
curframe(rect).copyTo(tempimg);
}else if(curframe.size().width==480){
cv::Rect rect(0, 0, 480,640);
curframe(rect).copyTo(tempimg);
}else if(curframe.size().width==288){
cv::Rect rect(0, 0, 288,352);
curframe(rect).copyTo(tempimg);
}else if(curframe.size().width==352){
cv::Rect rect(0, 0, 352,288);
curframe(rect).copyTo(tempimg);
}
//此处要进行判断,避免系统崩溃
if(tempimg.size().width>0){
bool jg1=cv::imwrite("./server/"+imageName+".jpg", tempimg);
bool jg2=cv::imwrite("./web/server/"+imageName+".jpg", tempimg);
if(jg1 and jg2)
{
return true;
}else
{
return false;
}
}else{
return false;
}