用OpenCV随机显示 一个圆圈,并保存成文件
2011-08-12 12:52
471 查看
用OpenCV 2.2 随机显示圆圈,并保存成test.avi文件
这程序可以用来作为 Kalman, Particle Filter 的追踪目标。
#include <stdlib.h>
#include <math.h>
#include "opencv2/opencv.hpp"
using namespace cv;
bool inRange (double x, double lowerBand, double upperBand)
{
return (x >= lowerBand) && (x <= upperBand);
}
int main()
{
int winWidth = 480;
int winHeight = 320;
char winName[] = "Particle Filter Sample";
int targetRadius = 5;
int targetRangeWidth = 10;
int targetRangeHeight = 10;
Mat image(winHeight, winWidth, CV_8UC3);
Point2i target(winWidth / 2, winHeight / 2);
// record video
VideoWriter record("test.avi", CV_FOURCC('D','I','V','X'), 30, Point(winWidth, winHeight), true);
srand(time(0));
for (;;) {
// Clears Previous target
circle(image, target,
targetRadius, Scalar(0, 0, 0), -1);
target.x += rand() % (2 * targetRangeWidth) - targetRangeWidth;
target.y += rand() % (2 * targetRangeHeight) - targetRangeHeight;
if (!inRange(target.x, 0, winWidth)) {
target.x = winWidth / 2;
}
if (!inRange(target.y, 0, winHeight)) {
target.y = winHeight / 2;
}
circle(image, target,
targetRadius, Scalar(255, 255, 255), -1);
imshow(winName, image);
record << image;
if(waitKey(30) == 27)
break;
}
return 0;
}
这程序可以用来作为 Kalman, Particle Filter 的追踪目标。
#include <stdlib.h>
#include <math.h>
#include "opencv2/opencv.hpp"
using namespace cv;
bool inRange (double x, double lowerBand, double upperBand)
{
return (x >= lowerBand) && (x <= upperBand);
}
int main()
{
int winWidth = 480;
int winHeight = 320;
char winName[] = "Particle Filter Sample";
int targetRadius = 5;
int targetRangeWidth = 10;
int targetRangeHeight = 10;
Mat image(winHeight, winWidth, CV_8UC3);
Point2i target(winWidth / 2, winHeight / 2);
// record video
VideoWriter record("test.avi", CV_FOURCC('D','I','V','X'), 30, Point(winWidth, winHeight), true);
srand(time(0));
for (;;) {
// Clears Previous target
circle(image, target,
targetRadius, Scalar(0, 0, 0), -1);
target.x += rand() % (2 * targetRangeWidth) - targetRangeWidth;
target.y += rand() % (2 * targetRangeHeight) - targetRangeHeight;
if (!inRange(target.x, 0, winWidth)) {
target.x = winWidth / 2;
}
if (!inRange(target.y, 0, winHeight)) {
target.y = winHeight / 2;
}
circle(image, target,
targetRadius, Scalar(255, 255, 255), -1);
imshow(winName, image);
record << image;
if(waitKey(30) == 27)
break;
}
return 0;
}
相关文章推荐
- opencv::将两幅图像合并后,在同一个窗口显示;并将合并的图像流保存成视频文件
- 网络爬虫,用C#做一个网络爬虫demo,功能有保存网页、图片、js文件、等等其他的文件。有界面显示,有代码注释。
- OpenCV显示摄像头图像保存成bmp文件
- 输入一个整数,将此整数保存到文件中,以记事本打开,显示同样的内容
- 建立一个文本文件in.txt,在其中输入若干个正整数,中间用空格分隔,然后保存起来;在窗体上添加一个命令按钮和一个标签框,当单击命令按钮时将in.txt文件中存放的所有的能被3整除的数的和显示在标签框
- 将数据库内表中的数据导出到txt文档中,并且显示一个对话框,提示用户保存文件的位置
- opencv中在屏幕上每隔几秒显示一个点,并且保存点的坐标
- 利用OpenCV提取图像的边缘,并将检测的边缘重新保存在一个新的文件中
- C# 保存图像文件到SQL SERVER数据库,再读取该文件并显示
- Python下使用OpenCV——图像显示与保存
- openCV保存XML文件基本操作
- 把配置文件以json字符串格式保存,并读取放到一个map中
- C#按键打开文件选择对话框,并把选择好的路径保存/显示到textBox
- 请从键盘随机输入5个整数保存到List中,并按倒序、从大到小的顺序显示出来
- 如何让文件夹内所有文件名显示在一个Excel文件
- 接收一个文件内容,通过读取开始和结束标志,分别将其内容保存到不同的文件中
- 网站的图片有时不显示,因为网站文件未放到根目录下,而套了一个文件夹放到目录下
- OpenCV——图片的加载、显示、保存(python)
- OpenGL加载、显示、截图、保存位图文件
- shell 实现统计一个网段的IP和mac对应关系并保存到文件mac.txt