0

私は生物学者で、実験的な仕事のために、スライド ガラス上のあらゆる動きを検出できるソフトウェアを開発したいと考えています。

次のコードを変更して、フレーム全体ではなく、特定の xy 座標を中心とした目的の半径円内でモーションを検出できるようにします。どのような変更が必要か教えていただけますか?

from SimpleCV import *

from SimpleCV import VirtualCamera
#from time import *
vir = VirtualCamera("video.mpg", "video")
vir.getImage().show()
cam = Camera()
threshold = 0.2 # if mean exceeds this amount do something

while True:
        previous = vir.getImage() #grab a frame
        #time.sleep(0.5) #wait for half a second
        current = vir.getImage() #grab another frame
        diff = current - previous
        lines = diff.findLines(threshold=1, minlinelength=1)
        lines.draw(width=2)
        current.addDrawingLayer(diff.dl())  
        matrix = diff.getNumpy()
        mean = matrix.mean()
        current.show()

        if mean >= threshold:
                print "Motion Detected"
                print mean
4

1 に答える 1

1

C++ で OpenCV を使用する:

//Subtract consecutive frames
cv::Mat matN=cv::imread("frame1.jpg");
cv::Mat matM=cv::imread("frame2.jpg");
cv::Mat matDiff=abs(matM-matN);

//Set region of interest (subframe)
int x(10),y(10),width(30),height(40);
cv::Rect myRegionOfInterest(x,y,width,height);

//Define motion
double Threshold=0.1;
double nze=cv::countNonZero( matDiff(myRegionOfInterest) );
double motionFactor=nze/(width*height*C); //C=255 for uchar, C=1 for binary, etc.
if (motionFactor>Threshold)
 std::cout<<"Motion detected at specific ROI";
于 2014-01-22T13:30:51.520 に答える