C 中视频的OpenCV Canny边缘检测
OpenCV Canny Edge detection of a video in C++
我正在从OpenCV食谱中学习OpenCV。在此,他在视频中给出了Canny Edge检测的代码。这是他尝试的代码。
#include "cv.h"
#include "highgui.h"
#include <string>
using namespace cv;
using namespace std;
void canny (Mat& img, Mat& out)
{
// Convert image to gray
if (img.channels () == 3)
{
cvtColor (img, out, CV_BGR2GRAY);
}
Canny (out, out, 100, 200);
threshold (out, out, 128, 255, THRESH_BINARY_INV);
}
class VideoProcessor
{
private:
VideoCapture capture;
bool callIt;
void* process (Mat&, Mat&);
string windowNameInput;
string windowNameOutput;
int delay;
long fnumber;
long frameToStop;
bool stop;
public:
VideoProcessor () : callIt (true), delay (0), fnumber (0), stop (false), frameToStop (-1) {};
int getFrameRate ()
{
return capture.get (CV_CAP_PROP_FPS);
}
void setFrameProcessor (void* frameProcessingCallback (Mat&, Mat&))
{
process = frameProcessingCallback;
}
bool setInput (string filename)
{
fnumber = 0;
capture.release ();
return capture.open (filename);
}
void displayInput (string wn)
{
windowNameInput = wn;
namedWindow (windowNameInput);
}
void displayOutput (string wn)
{
windowNameOutput = wn;
namedWindow (windowNameOutput);
}
void dontDisplay ()
{
destroyWindow (windowNameInput);
destroyWindow (windowNameOutput);
windowNameInput.clear ();
windowNameOutput.clear ();
}
void run ()
{
Mat frame;
Mat output;
if (!isOpened ())
{
return;
}
stop = false;
while (!isStopped ())
{
if (!readNextFrame (frame))
{
break;
}
if (windowNameInput.length () != 0)
{
imshow (windowNameInput, frame);
}
if (callIt)
{
process (frame, output);
fnumber++;
}
else
{
output = frame;
}
if (windowNameOutput.length () != 0)
{
imshow (windowNameOutput, output);
}
if (delay >= 0 && waitKey (delay) >= 0)
{
stopIt ();
}
if (frameToStop >= 0 && getFrameNumber () == frameToStop)
{
stopIt ();
}
}
}
void stopIt ()
{
stop = true;
}
bool isStopped ()
{
return stop;
}
bool isOpened ()
{
capture.isOpened ();
}
void setDelay (int d)
{
delay = d;
}
bool readNextFrame (Mat& frame)
{
return capture.read (frame);
}
void callProcess ()
{
callIt = true;
}
void dontCallProcess ()
{
callIt = false;
}
void stopAtFrameNo (long frame)
{
frameToStop = frame;
}
long getFrameNumber ()
{
long fnum = static_cast <long> (capture.get (CV_CAP_PROP_POS_FRAMES));
return fnum;
}
};
int main ()
{
VideoProcessor processor;
processor.setInput ("video2.MOV");
processor.displayInput ("Current Frame");
processor.displayOutput ("Output Frame");
processor.setDelay (1000 / processor.getFrameRate ());
processor.process (, canny);
processor.run ();
}
编译器在setFrameProcessor
函数中给出了错误,我无法修复它。任何人都可以帮忙吗?
您对功能指针的初始化是错误的。您需要将函数的引用传递给指针进程
void setFrameProcessor (void frameProcessingCallback (Mat&, Mat&))
{
process = &frameProcessingCallback;
}
另一个简单的示例:
#include <stdio.h>
void A()
{
printf("A");
}
void B(void A(void))
{
void (*f_ptr)(void);
f_ptr = &A;
f_ptr();
}
int main()
{
B(A);
return 0;
}
请参阅以下链接以获取更多详细信息。
http://www.cprogramming.com/tutorial/function-pointers.html
顺便说一句,问题与标题无关。我建议更改标题。
相关文章:
- 使用CMake检测支持的C++标准
- SFML C++ Canny边缘检测双刃
- 彩色图像的边缘检测 CannyAlgorithm.
- C++ OpenCV:检测两条线而不是一条线(Canny & findContours)
- ffmpeg/opencv 如何在分类后执行边缘检测 帧的类型
- 如何仅保留OpenCV Android库的模块(Canny Edge检测)
- 使用计算机视觉进行产品检测-使用opencv进行边缘检测
- 精明的边缘检测
- C 中视频的OpenCV Canny边缘检测
- 利用mpi进行sobel边缘检测
- 边缘检测-检测错误
- OpenCV在C++中的精明边缘检测
- Canny边缘检测器出现未处理的异常
- 我需要修改 Sobel 内核以进行对角线边缘检测.OpenCV和C++
- Sobel 边缘检测错误(OpenCV 错误:断言失败 (DIMS<=2&&Data&&(无符号)i0)
- 获得最大的结构(Canny边缘检测)
- 图形中的拐角和边缘检测
- 边缘检测opencv android
- 如何在iOS中使用Opencv检测嘴唇边缘
- 卡边缘检测OpenCV