#include "opencv2/opencv.hpp" /** @file webcam.cpp * @brief This is a simple test file to make sure your camera or video files can be opened using OpenCV * @author Ammar Qammaz (AmmarkoV) */ #include #include "cameraControl.hpp" #include "jointEstimator2D.hpp" #include "visualization.hpp" #include "../MocapNET2/MocapNETLib2/IO/commonSkeleton.hpp" using namespace cv; int main(int argc, char *argv[]) { unsigned int width = 640; unsigned int height = 480; const char * webcam = 0; int heatmapDebugVisualizations=0; //------------------------------------------------------ // Parse arguments //------------------------------------------------------ for (int i=0; ii+1) { webcam = argv[i+1]; } } else if (strcmp(argv[i],"--debug")==0) { heatmapDebugVisualizations = 1; } else if (strcmp(argv[i],"--size")==0) { if (argc>i+2) { width = atoi(argv[i+1]); height = atoi(argv[i+2]); } } } //------------------------------------------------------ VideoCapture cap(webcam); // open the default camera std::cerr<<"Trying to open webcam ("<> frame; if ( (frame.size().width>0) && (frame.size().height>0) ) { if ( !cropAndResizeCVMatToMatchSkeleton( &jointEstimator, frame, &result ) ) { fprintf(stderr,"Failed to crop input video\n"); } //imshow("Video Input Feed", frame); frame.copyTo(viewMat); // viewMat.setTo(Scalar(0,0,0)); //This needs to be done to get tensorflow output.. frame.convertTo(frame,CV_32FC3); //Keep time unsigned long startTime = GetTickCountMicrosecondsJointEstimator(); std::vector > heatmaps = getHeatmaps( &jointEstimator, frame.data, jointEstimator.inputWidth2DJointDetector, jointEstimator.inputHeight2DJointDetector ); if (heatmaps.size()>0) { if (heatmapDebugVisualizations) { visualizeHeatmaps(&jointEstimator,heatmaps,frameNumber); } estimate2DSkeletonsFromHeatmaps(&jointEstimator,&result,heatmaps); //Keep time unsigned long endTime = GetTickCountMicrosecondsJointEstimator(); elapsedTime += endTime - startTime; dj_drawExtractedSkeletons( viewMat, &result, jointEstimator.inputWidth2DJointDetector, jointEstimator.inputHeight2DJointDetector ); imshow("Skeletons", viewMat); } ++frameNumber; } else { std::cerr<<"Broken frame.. \n"; ++brokenFrames; } waitKey(1); if (brokenFrames>10) { break; } } if (frameNumber>0) { fprintf(stderr,"Elapsed time is %lu microsconds for %u frames\n",elapsedTime,frameNumber); fprintf(stderr,"Framerate : %0.2f fps\n",(float) elapsedTime/(1000* frameNumber)); } } // the camera will be deinitialized automatically in VideoCapture destructor return 0; }