This commit is contained in:
Alphyron 2020-12-16 16:30:32 +01:00
parent 55b12c05a8
commit 8e693d7954
4 changed files with 24 additions and 31 deletions

11
.gitignore vendored Normal file
View 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.

View File

@ -6,7 +6,7 @@ using namespace std;
using namespace cv;
uchar **matToArray( cv::Mat array);
int diffVec(Vec3b & first, Vec3b & second);
int main(int argc, char* argv[])
{
@ -17,10 +17,6 @@ int main(int argc, char* argv[])
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
// If the input is the web camera, pass 0 instead of the video file name
VideoCapture cap("teapot.mp4");
@ -30,8 +26,8 @@ int main(int argc, char* argv[])
cout << "Error opening video stream or file" << endl;
return -1;
}
Mat oldFrame;
cout << oldFrame << endl;
while(1){
Mat frame;
@ -47,16 +43,18 @@ int main(int argc, char* argv[])
continue;
}
cv::Mat newMat = cv::Mat(frame.rows, frame.cols, frame.type());
oldPixels = matToArray(oldFrame);
pixels = matToArray(frame);
cv::Mat newMat = cv::Mat(frame.rows, frame.cols, frame.type()); // frame.clone();
for(int i=0;i<frame.rows;i++){
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);
// ... do something to the color ....
@ -77,12 +75,11 @@ int main(int argc, char* argv[])
oldFrame = frame;
// Display the resulting frame
imshow( "Frame", newMat );
imshow( "Hans", frame );
imshow( "Live", frame );
imshow( "MotionDetection", newMat );
// Press ESC on keyboard to exit
char c=(char)waitKey(25);
char c=(char)waitKey(10);
if(c==27)
break;
}
@ -100,18 +97,3 @@ int main(int argc, char* argv[])
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;
}