Skip to content

Instantly share code, notes, and snippets.

#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace cv::bgsubcnt;
using namespace std;
int main( int argc, char** argv )
{
VideoCapture cap;
#include "bgsubcnt.h"
using namespace cv::bgsubcnt;
// Rest of the code is the same ...
Ptr<BackgroundSubtractor> pBgSub = createBackgroundSubtractorCNT();
// Rest of the code is the same ...
Ptr<BackgroundSubtractorCNT>
createBackgroundSubtractorCNT(int minPixelStability = 15,
bool useHistory = true,
int maxPixelStability = 15*60,
bool isParallel = true);
import numpy as np
import cv2
import bgsubcnt # 1. New import
# A temporary solution to OpenCV 3.1.0 bug
# with background subtractors
cv2.ocl.setUseOpenCL(False)
cap = cv2.VideoCapture('/home/userName/Downloads/opencv-3.1.0/samples/data/768x576.avi')
#!/bin/sh
if [ "$1" = "-h" ]; then
echo "Usage: $0 [filename]"
exit
fi
# Get the IP automatically - this will prompt for a password because of sudo usage
ip=`sudo arp-scan -localnet | perl -ne 'print $1 if /(\S+).*Rigol/i'`
if [ "$ip" = "" ]; then
#include <thread>
#include <tbb/concurrent_queue.h>
#include <tbb/pipeline.h>
volatile bool done = false; // volatile is enough here. We don't need a mutex for this simple flag.
struct ProcessingChainData
{
Mat img;
vector<Rect> faces, faces2;
Mat gray, smallImg;
};
//...
if( capture.isOpened() )
{
//...
tbb::concurrent_bounded_queue<ProcessingChainData *> guiQueue;
guiQueue.set_capacity(2); // TBB NOTE: flow control so the pipeline won't fill too much RAM
auto pipelineRunner = thread( detectAndDrawTBB, ref(capture), ref(guiQueue), ref(cascade), ref(nestedCascade), scale, tryflip );
//...
// TBB NOTE: This usage below is just for the tbb demonstration.
// It is not an example for good OO code. The lambda
// expressions are used to easily show the correleation
// between the original code and the tbb code.
void detectAndDrawTBB( VideoCapture &capture,
tbb::concurrent_bounded_queue<ProcessingChainData *> &guiQueue,
CascadeClassifier& cascade,
CascadeClassifier& nestedCascade,
double scale, bool tryflip )
{
class CountingManager
{
public:
CountingManager(Canvas &c)
{
c.notifyOnShapeCreate([&c, this](Shape* shape)
{ // User created a shape
if (shape->getType() == LineCrossing::type)
{ // Add the LineCrossing to out list
LineCrossing *pLineCrossing = (LineCrossing*) shape;