This repository has been archived by the owner on Dec 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcaptureimage.cpp
55 lines (48 loc) · 1.68 KB
/
captureimage.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
#include "captureimage.h"
CaptureImage::CaptureImage(QObject *parent) : QObject(parent)
{
}
void CaptureImage::process()
{
VideoCapture camera(cameraNumber);
QSerialPort* arduino;
arduino = new QSerialPort();
if(!arduino->isOpen()){
arduino->setPort(myPort);
arduino->open(QIODevice::ReadWrite);
arduino->setBaudRate(QSerialPort::Baud9600); //this is the same
arduino->setDataBits(QSerialPort::Data8);
arduino->setParity(QSerialPort::NoParity);
arduino->setStopBits(QSerialPort::OneStop);
arduino->setFlowControl(QSerialPort::NoFlowControl);
}
QThread::sleep(1);
vector<Mat> cameraStack;
for(char i = 0; i < 5; i++){
Mat frame;
Mat bgr[3]; //destination array
char message[10] = "eabcd";
arduino->write(&message[i],1);
arduino->flush();
QThread::sleep(1);
camera >> frame;
split(frame,bgr);//split source
cameraStack.push_back(bgr[0]);
char filename[20];
sprintf(filename,"~/Documents/test%d.png",i);
//cout << "Writing File " << filename <<std::endl;
cout << "getting data, "<< message[i]<<", " << (int)frame.at<unsigned char>(50,80)<<std::endl;
//imwrite(filename, frame);
}
Mat saturation = Mat::ones(cameraStack[1].size(),CV_8UC1);
Mat gradient;
for(unsigned int i = 0; i < 4; i++){
Mat thresh;
threshold(cameraStack[i],thresh,240,255,THRESH_BINARY);
saturation += ((i+1)*Mat::ones(cameraStack[i].size(),CV_8UC1)) & thresh;
}
gradient = (cameraStack[3]-cameraStack[0])/saturation;
imwrite("test.png", gradient);
arduino->close();
finished();
}