-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathcamera.cpp
103 lines (71 loc) · 1.85 KB
/
camera.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include <cmath>
#include "opencv2/video.hpp"
using namespace std;
using namespace cv;
int main(){
Mat oriDa = imread("dados.jpg", CV_LOAD_IMAGE_GRAYSCALE);
Mat masc = imread("dados.jpg", CV_LOAD_IMAGE_GRAYSCALE);
Mat chida = imread("cielo.jpg", CV_LOAD_IMAGE_GRAYSCALE);
Mat image2;
for (int i = 0; i < masc.rows; i++) {
for (int j = 0; j < masc.cols; j++) {
if (masc.at<uchar>(i, j)>200) {
masc.at<uchar>(i, j) = (uchar)(255);
}
else {
masc.at<uchar>(i, j) = (uchar)(0);
}
}
}
VideoCapture cap(0);// abre la cámara de default
if (!cap.isOpened())//revisa si se abrió correctamente
return -1;
for(;;){
Mat frame;
cap >> frame;//obtiene un nuevo cuadro de la cámara
cvtColor(frame, image2, COLOR_BGR2GRAY);
for (int i = 0; i < frame.rows; i++) {
for (int j = 0; j < frame.cols; j++) {
if (masc.at<uchar>(i, j) == 255) {
//****
oriDa.at<uchar>(i, j) = image2.at<uchar>(i, j);
//oriDa.at<uchar>(i, j) = chida.at<uchar>(i, j);
}
}
}
imshow("frame", oriDa);
if (waitKey(1) >= 0)
break;
}
return 0;
}
/*
Mat oriDa = imread("dados.jpg", CV_LOAD_IMAGE_GRAYSCALE);
Mat masc = imread("dados.jpg", CV_LOAD_IMAGE_GRAYSCALE);
Mat chida = imread("cielo.jpg", CV_LOAD_IMAGE_GRAYSCALE);
for (int i = 0; i < masc.rows; i++) {
for (int j = 0; j < masc.cols; j++) {
if (masc.at<uchar>(i, j)>200) {
masc.at<uchar>(i, j) = (uchar)(255);
}
else {
masc.at<uchar>(i, j) = (uchar)(0);
}
}
}
for (int i = 0; i < chida.rows; i++) {
for (int j = 0; j < chida.cols; j++) {
if (masc.at<uchar>(i, j) == 255) {
oriDa.at<uchar>(i, j) = chida.at<uchar>(i, j);
}
}
}
//-----
namedWindow("binary", WINDOW_AUTOSIZE);
imshow("binary", oriDa);
waitKey(0);
*/