Computer vision 使用fast(Opencv)提取特征点后分割对象

Computer vision 使用fast(Opencv)提取特征点后分割对象,computer-vision,Computer Vision,我有这段代码,我设法使用fast提取特征,然后使用Lucas kanade方法跟踪这些点,但现在我想在视频中的每个对象周围分割并绘制一个边界框。如有任何意见,将不胜感激。提前谢谢。这是代码 #include <stdio.h> #include <iostream> #include "opencv2/core.hpp" #include "opencv2/features2d.hpp" #include "opencv2/highgui.hpp" #include "o

我有这段代码,我设法使用fast提取特征,然后使用Lucas kanade方法跟踪这些点,但现在我想在视频中的每个对象周围分割并绘制一个边界框。如有任何意见,将不胜感激。提前谢谢。这是代码

#include <stdio.h>
#include <iostream>
#include "opencv2/core.hpp"
#include "opencv2/features2d.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/video/tracking.hpp"

using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
    bool addRemovePt = false;
    VideoCapture cap;
    TermCriteria termcrit(TermCriteria::COUNT | TermCriteria::EPS, 20, 0.03);
    Size subPixWinSize(10, 10), winSize(31, 31);
    cap.open(0);
    if (!cap.isOpened())
        return -1;
    namedWindow("Video", 1);
    float scalingFactor = 0.75;
    Mat gray, prevGray, image, frame;
    bool init = true;
    vector<Point2f> Points[2];
    int count = 0;
    while (true) {
        cap >> frame; // capture frame from webcam
        if (frame.empty())
            break;
        resize(frame, frame, Size(), scalingFactor, scalingFactor, INTER_AREA);
        frame.copyTo(image);
        cvtColor(image, gray, COLOR_BGR2GRAY); // change to grayscale
        if (init) {
            vector<KeyPoint> keypoints_1;
            Ptr<FastFeatureDetector> fastDetector = FastFeatureDetector::create(20);
            fastDetector->detect(gray, keypoints_1); // detect interest points using fast every 30 frames
            KeyPoint::convert(keypoints_1, Points[1]);
            init = false;
        }
        else if (!Points[0].empty()) {
            vector<uchar> status;
            vector<float> err;

            if (prevGray.empty()) {
                gray.copyTo(prevGray);
                cout << "once" << endl;
            }
            // Lucas-kannade optical flow
            calcOpticalFlowPyrLK(prevGray, gray, Points[0], Points[1], status, err, winSize, 3, termcrit, 0, 0.001);
            size_t i, k;
            for (i = k = 0; i < Points[1].size(); i++)
            {
                if (!status[i])
                    continue;
                Points[1][k++] = Points[1][i];
                circle(image, Points[1][i], 3, Scalar(0, 255, 0), -1, 8);
            }
            Points[1].resize(k);
        }

        imshow("Video", image);
        count++;
        if (count == 15) {
            count = 0;
            init = true;
        }
        if (waitKey(30) >= 0)
            break;
        swap(Points[1], Points[0]);
        swap(prevGray, gray);
    }
    cap.release();
    return 0;
}
#包括
#包括
#包括“opencv2/core.hpp”
#包括“opencv2/features2d.hpp”
#包括“opencv2/highgui.hpp”
#包括“opencv2/imgproc/imgproc.hpp”
#包括“opencv2/video/tracking.hpp”
使用名称空间std;
使用名称空间cv;
int main(int argc,字符**argv)
{
bool addRemovePt=false;
视频捕捉帽;
TermCriteria termcrit(TermCriteria::COUNT | TermCriteria::EPS,20,0.03);
大小亚像素winSize(10,10),winSize(31,31);
上限开放(0);
如果(!cap.isOpened())
返回-1;
namedWindow(“视频”,1);
浮动比例因子=0.75;
Mat gray、prevGray、图像、帧;
bool init=true;
向量点[2];
整数计数=0;
while(true){
cap>>帧;//从网络摄像头捕获帧
if(frame.empty())
打破
调整大小(帧、帧、大小()、缩放因子、缩放因子、内部区域);
frame.copyTo(图像);
cvtColor(图像、灰色、彩色);//更改为灰度
if(init){
向量关键点_1;
Ptr fastDetector=FastFeatureDetector::create(20);
fastDetector->detect(灰色,关键点_1);//每30帧使用fast检测兴趣点
KeyPoint::convert(keypoints_1,Points[1]);
init=false;
}
如果(!Points[0].empty()),则为else{
病媒状态;
矢量误差;
if(prevGray.empty()){
灰色。复制到(prevGray);

你能用你的输入和输出显示图像吗,最好能显示你想要达到的结果。现在还不清楚你想要达到什么。我想要达到的是,我有一个动态(动态)的实时视频源。我想识别视频中的所有对象,在每个对象周围画一个边界框并实时跟踪它们。我添加了一个图片示例。你知道第一帧中对象的初始位置/位置吗?在第一帧,我运行快速角点检测器并获取兴趣点。然后我使用lucas kanade跟踪这些点。我不知道知道你所说的物体的位置是什么意思吗?你看到我贴在上面的图片了吗?这是我所拥有的,这是我想要的图片链接。听起来你在问如何对给定位置的物体进行分类,对吗?你知道你将要识别哪些物体吗?