#include<iostream>
#include<core\core.hpp>
#include<opencv2\opencv.hpp>
using namespace std;
using namespace cv;
Mat bgImage;
void random_LineDemo();
int main(int argc,char** argv){
bgImage = imread("1.jpg");
if (bgImage.empty())
{
cout << "could not load image.." << endl;
return -1;
}
random_LineDemo();
waitKey(0);
return 0;
}
void random_LineDemo() {
RNG rng = (12345);
Point pt1;
Point pt2;
Mat bg = Mat::zeros(bgImage.size(), bgImage.type());
namedWindow("随机线模型", WINDOW_AUTOSIZE);
for(int i=0;i<100000;i++)
{
pt1.x = rng.uniform(0, bgImage.cols);
pt1.y = rng.uniform(0, bgImage.rows);
pt2.x = rng.uniform(0, bgImage.cols);
pt2.y = rng.uniform(0, bgImage.rows);
Scalar color = Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255));
if (waitKey(50) > 0) {
break;
}
line(bg, pt1, pt2, color, 1, 8);
imshow("随机线模型", bg);
}
}
#include<core\core.hpp>
#include<opencv2\opencv.hpp>
using namespace std;
using namespace cv;
Mat bgImage;
void random_LineDemo();
int main(int argc,char** argv){
bgImage = imread("1.jpg");
if (bgImage.empty())
{
cout << "could not load image.." << endl;
return -1;
}
random_LineDemo();
waitKey(0);
return 0;
}
void random_LineDemo() {
RNG rng = (12345);
Point pt1;
Point pt2;
Mat bg = Mat::zeros(bgImage.size(), bgImage.type());
namedWindow("随机线模型", WINDOW_AUTOSIZE);
for(int i=0;i<100000;i++)
{
pt1.x = rng.uniform(0, bgImage.cols);
pt1.y = rng.uniform(0, bgImage.rows);
pt2.x = rng.uniform(0, bgImage.cols);
pt2.y = rng.uniform(0, bgImage.rows);
Scalar color = Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255));
if (waitKey(50) > 0) {
break;
}
line(bg, pt1, pt2, color, 1, 8);
imshow("随机线模型", bg);
}
}