It works
This commit is contained in:
		
							parent
							
								
									55b12c05a8
								
							
						
					
					
						commit
						8e693d7954
					
				
							
								
								
									
										11
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,11 @@
 | 
				
			|||||||
 | 
					CMakeLists.txt.user
 | 
				
			||||||
 | 
					CMakeCache.txt
 | 
				
			||||||
 | 
					CMakeFiles
 | 
				
			||||||
 | 
					CMakeScripts
 | 
				
			||||||
 | 
					Testing
 | 
				
			||||||
 | 
					Makefile
 | 
				
			||||||
 | 
					cmake_install.cmake
 | 
				
			||||||
 | 
					install_manifest.txt
 | 
				
			||||||
 | 
					compile_commands.json
 | 
				
			||||||
 | 
					CTestTestfile.cmake
 | 
				
			||||||
 | 
					_deps
 | 
				
			||||||
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								MotionDetection
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								MotionDetection
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							@ -6,7 +6,7 @@ using namespace std;
 | 
				
			|||||||
using namespace cv;
 | 
					using namespace cv;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
uchar **matToArray( cv::Mat array);
 | 
					uchar **matToArray( cv::Mat array);
 | 
				
			||||||
 | 
					int diffVec(Vec3b & first, Vec3b & second);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int main(int argc, char* argv[])
 | 
					int main(int argc, char* argv[])
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@ -17,10 +17,6 @@ int main(int argc, char* argv[])
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    int childProcesses = procRank -1;
 | 
					    int childProcesses = procRank -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //2D array - used to store ther Mat Object values
 | 
					 | 
				
			||||||
    uchar **pixels = NULL;
 | 
					 | 
				
			||||||
    uchar **oldPixels = NULL;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // Create a VideoCapture object and open the input file
 | 
					    // Create a VideoCapture object and open the input file
 | 
				
			||||||
    // If the input is the web camera, pass 0 instead of the video file name
 | 
					    // If the input is the web camera, pass 0 instead of the video file name
 | 
				
			||||||
    VideoCapture cap("teapot.mp4");
 | 
					    VideoCapture cap("teapot.mp4");
 | 
				
			||||||
@ -30,8 +26,8 @@ int main(int argc, char* argv[])
 | 
				
			|||||||
        cout << "Error opening video stream or file" << endl;
 | 
					        cout << "Error opening video stream or file" << endl;
 | 
				
			||||||
        return -1;
 | 
					        return -1;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Mat oldFrame;
 | 
					    Mat oldFrame;
 | 
				
			||||||
    cout << oldFrame << endl;
 | 
					 | 
				
			||||||
    while(1){
 | 
					    while(1){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Mat frame;
 | 
					        Mat frame;
 | 
				
			||||||
@ -47,16 +43,18 @@ int main(int argc, char* argv[])
 | 
				
			|||||||
            continue;
 | 
					            continue;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        cv::Mat newMat = cv::Mat(frame.rows, frame.cols, frame.type());
 | 
					        cv::Mat newMat = cv::Mat(frame.rows, frame.cols, frame.type()); // frame.clone();
 | 
				
			||||||
 | 
					 | 
				
			||||||
        oldPixels = matToArray(oldFrame);
 | 
					 | 
				
			||||||
        pixels = matToArray(frame);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for(int i=0;i<frame.rows;i++){
 | 
					        for(int i=0;i<frame.rows;i++){
 | 
				
			||||||
            for(int j=0;j<frame.cols;j++){
 | 
					            for(int j=0;j<frame.cols;j++){
 | 
				
			||||||
                int diff = std::abs(pixels[i][j] - oldPixels[i][j]);
 | 
					                auto oldPxl = oldFrame.at<Vec3b>(i, j);
 | 
				
			||||||
 | 
					                auto currPxl = frame.at<Vec3b>(i, j);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                if(diff > 10) {
 | 
					                // Summiert die Vekotren nach der euklidischen Norm (Von OpenCV)
 | 
				
			||||||
 | 
					                int diff = norm(oldPxl - currPxl);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                if(diff > 20) {
 | 
				
			||||||
                    Vec3b & color = newMat.at<Vec3b>(i,j);
 | 
					                    Vec3b & color = newMat.at<Vec3b>(i,j);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    // ... do something to the color ....
 | 
					                    // ... do something to the color ....
 | 
				
			||||||
@ -77,12 +75,11 @@ int main(int argc, char* argv[])
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        oldFrame = frame;
 | 
					        oldFrame = frame;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Display the resulting frame
 | 
					        imshow( "Live", frame );
 | 
				
			||||||
        imshow( "Frame", newMat );
 | 
					        imshow( "MotionDetection", newMat );
 | 
				
			||||||
        imshow( "Hans", frame );
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Press  ESC on keyboard to exit
 | 
					        // Press  ESC on keyboard to exit
 | 
				
			||||||
        char c=(char)waitKey(25);
 | 
					        char c=(char)waitKey(10);
 | 
				
			||||||
        if(c==27)
 | 
					        if(c==27)
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -99,19 +96,4 @@ int main(int argc, char* argv[])
 | 
				
			|||||||
    MPI_Finalize();
 | 
					    MPI_Finalize();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
uchar **matToArray( cv::Mat array)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    uchar **pixels = new uchar *[array.rows];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    for (int i = 0; i < array.rows; i++)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        //IMPORTANT!! Channels are BGR
 | 
					 | 
				
			||||||
        pixels[i] = new uchar[array.cols * array.channels()];
 | 
					 | 
				
			||||||
        pixels[i] = array.ptr<uchar>(i);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return pixels;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user