Commit e1126306 authored by wanghailong's avatar wanghailong

解决初始化失败的问题

parent 26243a88
......@@ -57,9 +57,9 @@ void CBM_model::Initialize()
// _writer10.open("DPM.avi",cv::VideoWriter::fourcc('X','V','I','D'),30,cv::Size(new_width,new_height),1);
mog_fg = cv::Mat::zeros(cv::Size(new_width, new_height), CV_8UC1);
mog_fg2 = cv::Mat::zeros(cv::Size(new_width, new_height), CV_8UC1);
imgStatic = cv::Mat::zeros(cv::Size(new_width, new_height), CV_8UC3);
// mog_fg = cv::Mat::zeros(cv::Size(new_width, new_height), CV_8UC1);
// mog_fg2 = cv::Mat::zeros(cv::Size(new_width, new_height), CV_8UC1);
// imgStatic = cv::Mat::zeros(cv::Size(new_width, new_height), CV_8UC3);
my_mog_fg = myCreateImage( new_width, new_height, 1);
my_mog_fg2 = myCreateImage( new_width, new_height, 1);
......@@ -196,9 +196,9 @@ bool CBM_model::Motion_Detection(myImage *img)
staticFG_pixel_num_pre = staticFG_pixel_num_now;
staticFG_pixel_num_now = check_foreground2(my_imgStatic);
myImage_2_opencv(my_imgStatic,imgStatic);
myImage_2_opencv(my_mog_fg,mog_fg);
myImage_2_opencv(my_mog_fg2,mog_fg2);
// myImage_2_opencv(my_imgStatic,imgStatic);
// myImage_2_opencv(my_mog_fg,mog_fg);
// myImage_2_opencv(my_mog_fg2,mog_fg2);
// cv::imwrite("static_obj.jpg", imgStatic);
// cv::imwrite("Long-term.jpg", mog_fg);
// cv::imwrite("Short-term.jpg", mog_fg2);
......
......@@ -91,7 +91,7 @@ public:
int TEMPORAL_RULE;
//VideoDetails *_video;//input video
cv::VideoWriter _writer6, _writer7, _writer8, _writer9, _writer10;
//cv::VideoWriter _writer6, _writer7, _writer8, _writer9, _writer10;
CBM_model(myImage * input, int set_MOG_LearnFrame, int set_min_area, int set_buffer_len, float set_resize, myImage * mask);
~CBM_model();
void Initialize();
......@@ -143,9 +143,9 @@ public:
myImage * maskROI;
myImage * input_temp;
private:
cv::Mat mog_fg;//long term
cv::Mat mog_fg2;//short term
cv::Mat imgStatic;
// cv::Mat mog_fg;//long term
// cv::Mat mog_fg2;//short term
// cv::Mat imgStatic;
myImage * my_mog_fg;//long term
......
cmake_minimum_required(VERSION 2.8)
project(ObjLeft)
find_package(OpenCV 4.1.1 REQUIRED)
find_package(OpenCV REQUIRED)
link_directories(${MYPROJECT_DIR})
......
......@@ -28,13 +28,13 @@ double INPUT_RESIZE;
bool DetectAnomaly::detectAnomaly(cv::Mat img, vector<vector<int>>* resultLocation)
{
yolo_test = img.clone();
cv::Rect rect(0,610,2400,910);
img = img(rect);
cv::resize(img, img,cv::Size(2400*0.25, 910*0.25), cv::INTER_CUBIC);
img.copyTo(myimg);
medianBlur(mat_myimg, mat_myimg, 3);
opencv_2_myImage(myimg, myimg1); //transfer opencv data to myimage data
//img.copyTo(*myimg);
myimg = &img;
medianBlur(*mat_myimg, *mat_myimg, 3);
opencv_2_myImage(*myimg, myimg1); //transfer opencv data to myimage data
/************************************************************************/
/* abandoned object detection algorithm */
......@@ -51,9 +51,9 @@ bool DetectAnomaly::detectAnomaly(config cfg, cv::Mat img, vector<vector<int>>*
img = img(rect);
//cv::resize(img, img,cv::Size(2400*0.25, 910*0.25), cv::INTER_CUBIC);
cv::resize(img, img,cv::Size(cfg.image_width * cfg.input_resize, cfg.image_height * cfg.input_resize), cv::INTER_CUBIC);
img.copyTo(myimg);
medianBlur(mat_myimg, mat_myimg, 3);
opencv_2_myImage(myimg, myimg1); //transfer opencv data to myimage data
myimg = &img;
medianBlur(*mat_myimg, *mat_myimg, 3);
opencv_2_myImage(*myimg, myimg1); //transfer opencv data to myimage data
/************************************************************************/
/* abandoned object detection algorithm */
......@@ -142,8 +142,9 @@ DetectAnomaly::DetectAnomaly()
mymask = myCreateImage(cfgAnomaly.image_width, cfgAnomaly.image_height, 3);
myInverse(mymask, mymask);
myimg1 = myCreateImage(cfgAnomaly.image_width, cfgAnomaly.image_height, 3);
myimg = cv::Mat(cv::Size(cfgAnomaly.image_width, cfgAnomaly.image_height), CV_8UC3);
myimg.copyTo(mat_myimg);
myimg = new cv::Mat(cv::Size(cfgAnomaly.image_width, cfgAnomaly.image_height), CV_8UC3);
//*myimg.copyTo(*mat_myimg);
mat_myimg = myimg;
// mat_myimg(myimg, 0);
// set roi
......@@ -163,15 +164,15 @@ DetectAnomaly::DetectAnomaly()
cv::polylines(Image1, PointArray, arr, 1,true, cv::Scalar(255, 255, 255),5,8,0);
cv::fillPoly(Image1, ppt, arr, 1, cv::Scalar(255, 255, 255),0);
cv::threshold(Image1, Image1, 254, 255,THRESH_BINARY);
mask = Image1.clone();
mask = &Image1;
opencv_2_myImage(mask, mymask);
opencv_2_myImage(*mask, mymask);
#ifdef DEBUG
//cv::imwrite("mask.jpg", Image1);
cv::waitKey(1);
//cv::imwrite("mask.jpg", *mask);
//cv::waitKey(1);
//cvReleaseImage(&Image1);
#endif
_objleft.ObjLeftSet(myimg1, cfgAnomaly.gmm_learn_frame, cfgAnomaly.min_fg, cfgAnomaly.buffer_length, mymask);
_objleft.ObjLeftSet(myimg1, cfgAnomaly.gmm_learn_frame, cfgAnomaly.min_fg, cfgAnomaly.buffer_length, mymask, mask);
#ifdef DEBUG
printf("Finished initialization.\n");
#endif
......@@ -220,8 +221,9 @@ DetectAnomaly::DetectAnomaly(config cfg) : cfgAnomaly(cfg)
mymask = myCreateImage(cfgAnomaly.image_width, cfgAnomaly.image_height, 3);
myInverse(mymask, mymask);
myimg1 = myCreateImage(cfgAnomaly.image_width, cfgAnomaly.image_height, 3);
myimg = cv::Mat(cv::Size(cfgAnomaly.image_width, cfgAnomaly.image_height), CV_8UC3);
myimg.copyTo(mat_myimg);
myimg = new cv::Mat(cv::Size(cfgAnomaly.image_width, cfgAnomaly.image_height), CV_8UC3);
//myimg.copyTo(mat_myimg);
mat_myimg = myimg;
// mat_myimg(myimg, 0);
// set roi
......@@ -251,15 +253,15 @@ DetectAnomaly::DetectAnomaly(config cfg) : cfgAnomaly(cfg)
cv::polylines(Image1, PointArray, arr, 1,true, cv::Scalar(255, 255, 255),5,8,0);
cv::fillPoly(Image1, ppt, arr, 1, cv::Scalar(255, 255, 255),0);
cv::threshold(Image1, Image1, 254, 255, THRESH_BINARY);
mask = Image1.clone();
mask = &Image1;
opencv_2_myImage(mask, mymask);
opencv_2_myImage(*mask, mymask);
#ifdef DEBUG
//cv::imwrite("mask.jpg", Image1);
cv::waitKey(1);
cv::imwrite("mask.jpg", Image1);
//cv::waitKey(1);
//cvReleaseImage(&Image1);
#endif
_objleft.ObjLeftSet(myimg1, cfgAnomaly.gmm_learn_frame, cfgAnomaly.min_fg, cfgAnomaly.buffer_length, mymask);
_objleft.ObjLeftSet(myimg1, cfgAnomaly.gmm_learn_frame, cfgAnomaly.min_fg, cfgAnomaly.buffer_length, mymask,mask);
#ifdef DEBUG
printf("Finished initialization.\n");
#endif
......
......@@ -44,13 +44,13 @@ private:
cv::Point PointArray1[4];
cv::Point *PointArray[2] = {&PointArray1[0], &PointArray1[2]};
cv::Mat mask;
cv::Mat* mask;
myImage *mymask;
cv::Mat myimg;
cv::Mat* myimg;
myImage *myimg1;
cv::Mat mat_myimg;
cv::Mat* mat_myimg;
ObjLeftDetect _objleft;
bool obj_left;
......@@ -63,7 +63,6 @@ public:
DetectAnomaly();
DetectAnomaly(config cfg);
cv::Mat yolo_test;
~DetectAnomaly();
};
......
This diff is collapsed.
......@@ -31,11 +31,11 @@ public:
bool process(myImage * input, vector<vector<int>>* resultLocation);
CBM_model *_CBM_model;
//cv::VideoWriter _writer1, _writer2;
cv::Mat A, B;
//cv::Mat A, B;
int ** image;
myFloatColor * connect_colors;
void ObjLeftSet(myImage *input, int set_MOG_LearnFrame, int set_min_area, int set_buffer_len, myImage *mask);
void ObjLeftSet(myImage *input, int set_MOG_LearnFrame, int set_min_area, int set_buffer_len, myImage *mask, cv::Mat* cvmask);
private:
//SYSTEMTIME st;
......@@ -55,9 +55,9 @@ private:
int new_width, new_height;
vector<Obj_info *> alarmList;
myImage * myimg1, * myimg2;
cv::Mat ImgSynopsis;
myImage * _ImgSynopsis;
//myImage * myimg1, * myimg2;
//cv::Mat ImgSynopsis;
//myImage * _ImgSynopsis;
int Spatial_Temporal_Search( int ** Image, int i, int j, myFloatColor * colors, int time_stamp,int my_label);
int spatial_flood( bool ** foreground, int i, int j);
......@@ -70,7 +70,7 @@ private:
int pic_num = 0;
//get mask points
cv::Mat objmask;
cv::Mat *objmask;
std::vector<std::vector<cv::Point>> contours;
};
......
......@@ -40,8 +40,8 @@ int main()
opt.bottom_left_y = 853;
opt.bottom_right_x = 2168;
opt.bottom_right_y = 842;
//DetectAnomaly* detect = new DetectAnomaly(opt);
DetectAnomaly* detect = new DetectAnomaly();
DetectAnomaly* detect = new DetectAnomaly(opt);
//DetectAnomaly* detect = new DetectAnomaly();
int pic_num = 0;
#ifdef DEBUG
//cv::VideoWriter _writer;
......@@ -65,8 +65,8 @@ int main()
// continue;
// }
//obj_left = detect->detectAnomaly(opt,qImg,&resultLocation);
obj_left = detect->detectAnomaly(qImg,&resultLocation);
obj_left = detect->detectAnomaly(opt,qImg,&resultLocation);
//obj_left = detect->detectAnomaly(qImg,&resultLocation);
......@@ -80,32 +80,32 @@ int main()
delete results_map[0];
delete input_mats;
#ifdef DEBUG
// if (obj_left == true)
// {
if (obj_left == true)
{
// printf("alram!!\n");
printf("alram!!\n");
// for(int i = 0; i < resultLocation.size();i++){
// int x0 = resultLocation[i][0] * 4;
// int y0 = resultLocation[i][1] * 4 + 610;
// int x1 = resultLocation[i][2] * 4;
// int y1 = resultLocation[i][3] * 4 + 610;
for(int i = 0; i < resultLocation.size();i++){
int x0 = resultLocation[i][0] * 4;
int y0 = resultLocation[i][1] * 4 + 610;
int x1 = resultLocation[i][2] * 4;
int y1 = resultLocation[i][3] * 4 + 610;
// cv::Point p1(x0, y0);
// cv::Point p2(x1, y1);
// cv::rectangle(qImg, p1, p2, cv::Scalar(0, 255, 0), 2);
// }
// stringstream ss1;
// string outFile;
// ss1 << "abanoned_"
// << "show"
// << count
// << ".jpg";
// ss1 >> outFile;
// cv::imwrite(outFile.c_str(), qImg);
cv::Point p1(x0, y0);
cv::Point p2(x1, y1);
cv::rectangle(qImg, p1, p2, cv::Scalar(0, 255, 0), 2);
}
stringstream ss1;
string outFile;
ss1 << "abanoned_"
<< "show"
<< count
<< ".jpg";
ss1 >> outFile;
cv::imwrite(outFile.c_str(), qImg);
// count++;
// }
count++;
}
#endif
}
gettimeofday(&end, NULL);
......@@ -116,7 +116,7 @@ int main()
printf("Finished detec, then release ...\n");
#endif
delete detect;
//delete detect;
//system("pause");
return 0;
}
......@@ -9,7 +9,7 @@ project(yolo-trt VERSION 1.0)
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O3 -Wno-write-strings")
#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath -Wl,$ORIGIN")
find_package(OpenCV 4.1.1 REQUIRED)
find_package(OpenCV REQUIRED)
#cuda
#export PATH=/usr/local/cuda-10.2/bin:$PATH
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment