I am trying to implement MoG algorithm on my Jetson TK1. I am using OpenCV4Tegra 2.4. The code is successfully compiled but when I try to execute it I get this error : segmentation fault Any help please Thanks in advance
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;
}
}
}
For everyone who encountred such problems, don't mix the code written in OpenCV 3 with OpenCV2 In my code the error comes from the use of Pointer in the 7th line correct it it will works correctly