Skip to content

Commit

Permalink
Skip X frames in dpm
Browse files Browse the repository at this point in the history
  • Loading branch information
ddkang committed May 19, 2017
1 parent 7fad174 commit 8e2e99f
Show file tree
Hide file tree
Showing 3 changed files with 1,897 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cpp/dpm/Makefile
@@ -1,2 +1,2 @@
all:
g++ -Wall -O3 -std=c++1y `pkg-config --cflags opencv` -o dpm dpm.cpp `pkg-config --libs opencv`
g++ -Wall -O3 -std=c++1y `pkg-config --cflags opencv` -o dpm dpm.cpp -fopenmp `pkg-config --libs opencv`
38 changes: 29 additions & 9 deletions cpp/dpm/dpm.cpp
Expand Up @@ -9,14 +9,22 @@

#include <stdio.h>
#include <iostream>
#include <fstream>

using namespace cv::dpm;

constexpr size_t kNbFrames = 10000;
constexpr size_t kSkip = 30;


int main(int argc, char** argv) {
cv::Ptr<DPMDetector> detector = DPMDetector::create(
std::vector<std::string>(1, "bus.xml"));
std::string xml_fname = "person.xml";
std::string video_fname = "/lfs/1/ddkang/noscope/data/videos/elevator.mp4";

cv::Ptr<DPMDetector> detector = DPMDetector::create(
std::vector<std::string>(1, xml_fname));

cv::VideoCapture capture("/lfs/1/ddkang/noscope/data/videos/taipei-long.mp4");
cv::VideoCapture capture(video_fname);
// capture.set(CV_CAP_PROP_FRAME_WIDTH, 320);
// capture.set(CV_CAP_PROP_FRAME_HEIGHT, 240);

Expand All @@ -35,14 +43,19 @@ int main(int argc, char** argv) {
#endif
#endif

constexpr int kNbFrames = 100;
std::ofstream csv_file("elevator.csv", std::ofstream::out);

double total_time = 0;
cv::Mat frame;
for (int i = 0; i < kNbFrames; i++) {
const bool read_frame = capture.read(frame);
if (!read_frame) {
throw std::runtime_error("Failed to read frame.");
return -1;
size_t cur_frame = 0;
for (size_t i = 0; i < kNbFrames; i++) {
for (size_t j = 0; j < kSkip; j++) {
const bool read_frame = capture.read(frame);
if (!read_frame) {
throw std::runtime_error("Failed to read frame.");
return -1;
}
cur_frame++;
}

std::vector<DPMDetector::ObjectDetection> ds;
Expand All @@ -54,6 +67,13 @@ int main(int argc, char** argv) {
detector->detect(image, ds);
t = ((double) cv::getTickCount() - t) / cv::getTickFrequency(); //elapsed time

// FIXME
if (ds.size() > 0) {
csv_file << cur_frame << ",1\n";
} else {
csv_file << cur_frame << ",0\n";
}

total_time += t;
}

Expand Down

0 comments on commit 8e2e99f

Please sign in to comment.