我正在尝试在我的Jetson TK1上实现MoG算法。我正在使用OpenCV4Tegra 2.4。代码已成功编译,但当我尝试执行它时,我收到此错误:分段错误 请帮忙 提前致谢
int main()
{
cv::VideoCapture input("/home/ubuntu/MyExamples/MD0/highway.avi");
cv::Mat img, img_prev0, img_prev, frame, mask, thresh, gray_img, out_frame;
cv::Ptr<cv::BackgroundSubtractorMOG2> bgsubtractor;
cv::BackgroundSubtractorMOG2( 10, 2.5,true);
input.read(img);
img.copyTo(img_prev0);
//convert to grayscale and set the first frame
cv::cvtColor(img_prev0, img_prev, CV_BGR2GRAY);
// Apply Gaussian blur filter
cv::GaussianBlur(img_prev, img_prev, cv::Size(7, 7), 0);
cv::VideoWriter output("highwayMD.avi",CV_FOURCC('X','V','I','D'),30,cv::Size(input.get(CV_CAP_PROP_FRAME_WIDTH),input.get(CV_CAP_PROP_FRAME_HEIGHT)),0);
while(input.read(frame))
{
//convert to grayscale
cv::cvtColor(frame, gray_img, CV_BGR2GRAY);
cv::GaussianBlur(gray_img, gray_img, cv::Size(7, 7), 0);
//mog2
bgsubtractor->operator()(gray_img, mask,-1);
//cv::threshold(mask, thresh, 25, 255, cv::THRESH_BINARY);
//cv::dilate(thresh, thresh, 0); // 0 is the rectangle structural element
output.write(thresh);
cv::putText(mask, "Motion Detected", cv::Point(10, 20), cv::FONT_HERSHEY_SIMPLEX, 0.75, cv::Scalar(255,255,255),2);
cv::imshow("Camera", mask);
if(cv::waitKey(1) == 27)
{
//exit if ESC is pressed
break;
}
}
}
答案 0 :(得分:0)
对于遇到此类问题的每个人,请勿将用OpenCV 3编写的代码与OpenCV2混合使用 在我的代码中,该错误来自第7行中使用Pointer,更正了它,它将正常运行