forked from lulu1315/MessyCurves
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMask.cpp
49 lines (45 loc) · 1.17 KB
/
Mask.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <cstdlib>
#include "opencv2/core.hpp"
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
Point2f MaskedResetPos(int masksampling,Mat &Mask) {
Point2f pos;
pos.x=0.;
pos.y=0.;
int mcount=0;
int width =Mask.cols;
int height=Mask.rows;
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
if (Mask.at<uchar>(i, j) == 0) {
Mask.at<uchar>(i, j)=255;
mcount ++;
if (mcount == masksampling) {
pos.x=j;
pos.y=i;
return pos;
break;
}
}
}
}
//return pos;
}
Mat PreFillMask(Mat ima,int lumtreshold,int &maskcount) {
int mcount=0;
Mat PixelMask(ima.rows, ima.cols, CV_8UC1, Scalar(255));
int width =ima.cols;
int height=ima.rows;
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
if (ima.at<uchar>(i, j) < lumtreshold) {
PixelMask.at<uchar>(i, j)=0;
mcount++;
}
}
}
maskcount=mcount;
return PixelMask;
}