박민혀기
CELLON 2023_03_12 (LAN 통신 제외한 최종 투입) 본문
1. ROI마다 Accuracy 값 지정 OK
2. 촬영시 Accuracy 값 변경됨 OK
->Accuracy와 결과값 갭차이
3. ROI 지정중 Rect Show
4. ROI 선 굵기 조정 OK
5. 회색값 변화 OK
6. 노란색 오차범위 확대 OK
7. Acc 각각 저장, 읽기 OK
8. 현재 ROI 개수 UI 표시 OK
9. 노말모드에서 Frame 정지 -> 3번 적용 NO
-> L 한 번 클릭 후 드래그 놓으면 ROI 지정 완료
-> ROI 지정중 정지화면일 경우 중간에 제품이 흔들리면?
10. "=CELLON" 위치(터치 포함) 조정 OK
11. "=CELLON" 색갈 변경 OK
12. RUN, SET 현재 상태 표시 OK
13. RUN모드시 현제 지정 ROI 개수 알람 끄기 OK
//#include <stdio.h>
#include <unistd.h>
#include <iostream>
#include <time.h>
#include "opencv2/opencv.hpp"
#include <wiringPi.h>
#include <math.h>
#define WEB_CAM 0
#define INPUT_PORT 22 //INPUT5
#define INPUT_DATA_RESET 27 //INPUT4
using namespace std;
using namespace cv;
unsigned int Number_of_ROI = 1;
unsigned int Accuracy_Percent[5];
unsigned int Number_of_ROI_Temp;
unsigned int Accuracy_Percent_Temp[5];
int flag = 0;
bool Setting_Mode_Flag = false;
bool Config_Flag = false;
unsigned int Compare_Total, Compare_Good, Compare_Bad;
VideoCapture cap;
Mat frame, Show_Frame, Inspect_ROI;
vector<Mat> Standard_ROI;
Point temp, temp2;
vector<Point> Inspect_ROI_Point;
vector<Point> State_Message_Point;
vector<String> State_Message_S;
Point Rectangle_Point_x = Point(90, 90);
Point Rectangle_Point_y = Point(165, 90);
Size Rectangle_Size = Size(20, 15);
Point Reset_Button_Point = Point(135, 230);
Size Reset_Button_Size = Point(50, 20);
int button_dis = 30;
double Message_Font_Size = 0.4;
Point Resolution_Point = Point(90, 200);
unsigned int width, height;
int State_Message_Flag = 0;
char img_data_addr[40] = "/home/cellon/CELLON/";
char data_addr[40] = "/home/cellon/CELLON/Log_data.txt";
char Fput_STR[100];
char total_data_addr[40] = "/home/cellon/CELLON/total_data.txt";
char good_data_addr[40] = "/home/cellon/CELLON/good_data.txt";
char bad_data_addr[40] = "/home/cellon/CELLON/bad_data.txt";
const int Led[] = { 18, 23, 24 }; //Led[0] = Ready, Led[1] = Bad, Led[2] = Good
bool start_signal = false;
///////////////////////Count Segment/////////////////////////
void State_Message() {
if (State_Message_S[6] != State_Message_S[7]) {
State_Message_S[0] = State_Message_S[1];
State_Message_S[1] = State_Message_S[2];
State_Message_S[2] = State_Message_S[3];
State_Message_S[3] = State_Message_S[4];
State_Message_S[4] = State_Message_S[5];
State_Message_S[5] = State_Message_S[6];
State_Message_S[6] = State_Message_S[7];
}
for (int i = 6; i >= 0; i--) {
putText(Show_Frame, State_Message_S[i], State_Message_Point[i], FONT_HERSHEY_DUPLEX, Message_Font_Size, Scalar(0, 0, 0), 2);
putText(Show_Frame, State_Message_S[i], State_Message_Point[i], FONT_HERSHEY_DUPLEX, Message_Font_Size, Scalar(220, 220, 220), 1);
}
}
void Compare_State(Scalar state_scalar) {
rectangle(Show_Frame, Rect(width - 135, height - 30, 95, 25), Scalar(0, 0, 0), -1);
rectangle(Show_Frame, Rect(width - 130, height - 25, 85, 15), state_scalar, -1);
}
void Compare_Result() {
char Compare_Total_S[15], Compare_Good_S[15], Compare_Bad_S[15];
sprintf(Compare_Total_S, "TOTAL : %d", Compare_Total);
sprintf(Compare_Good_S, "GOOD : %d", Compare_Good);
sprintf(Compare_Bad_S, "BAD : %d", Compare_Bad);
putText(Show_Frame, Compare_Total_S, Point(width - 135, height - 70), FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 0, 0), 3);
putText(Show_Frame, Compare_Total_S, Point(width - 135, height - 70), FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 255, 0), 1);
putText(Show_Frame, Compare_Good_S, Point(width - 135, height - 55), FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 0, 0), 3);
putText(Show_Frame, Compare_Good_S, Point(width - 135, height - 55), FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 255, 0), 1);
putText(Show_Frame, Compare_Bad_S, Point(width - 135, height - 40), FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 0, 0), 3);
putText(Show_Frame, Compare_Bad_S, Point(width - 135, height - 40), FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 255, 0), 1);
}
void ALAM_Marking() {
Point ALAM_Location = Point(8, 25);
putText(Show_Frame, "=", ALAM_Location, FONT_HERSHEY_DUPLEX, 1, Scalar(0, 0, 0), 5);
putText(Show_Frame, "CELLON", ALAM_Location + Point(30, -2), FONT_HERSHEY_DUPLEX, 0.6, Scalar(0, 0, 0), 4);
putText(Show_Frame, "=", ALAM_Location, FONT_HERSHEY_DUPLEX, 1, Scalar(0, 127, 255), 2);
putText(Show_Frame, "CELLON", ALAM_Location + Point(30, -2), FONT_HERSHEY_DUPLEX, 0.6, Scalar(0, 127, 255), 1);
char Cur_ROI[20];
sprintf(Cur_ROI, "ROI : %d/%d", Inspect_ROI_Point.size() / 2, Number_of_ROI);
if(Inspect_ROI_Point.size() / 2 != Number_of_ROI){
putText(Show_Frame, Cur_ROI, Point(width / 2, 25) + Point(-50, -2), FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 0, 0), 4);
putText(Show_Frame, Cur_ROI, Point(width / 2, 25) + Point(-50, -2), FONT_HERSHEY_DUPLEX, 0.5, Scalar(220, 220, 220), 1);
}
}
void Center_Marking(double width, double height) {
line(Show_Frame, Point(width / 2, height / 2 + 15), Point(width / 2, height / 2 - 15), Scalar(0, 0, 255), 1);
line(Show_Frame, Point(width / 2 + 15, height / 2), Point(width / 2 - 15, height / 2), Scalar(0, 0, 255), 1);
}
void Setting_Mode() {
char Accuracy_Percent_S[5];
char Number_of_ROI_S[5];
Point Title_Point = Point(5, 102);
Point Value_Point = Point(128, 102);
rectangle(Show_Frame, Rect(Title_Point - Point(2, 30) - Point(3, 3), Title_Point + Point(195, 200) + Point(3, 3)), Scalar(0, 0, 0), -1);
rectangle(Show_Frame, Rect(Title_Point - Point(2, 30), Title_Point + Point(195, 200)), Scalar(125, 125, 125), -1);
putText(Show_Frame, "ROI_Num", Title_Point, FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 0, 0), 3);
putText(Show_Frame, "ROI_Num", Title_Point, FONT_HERSHEY_DUPLEX, 0.5, Scalar(255, 255, 255), 1);
putText(Show_Frame, "ACC_1", Title_Point + Point(0, button_dis), FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 0, 0), 3);
putText(Show_Frame, "ACC_1", Title_Point + Point(0, button_dis), FONT_HERSHEY_DUPLEX, 0.5, Scalar(255, 255, 255), 1);
putText(Show_Frame, "ACC_2", Title_Point + Point(0, button_dis) * 2, FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 0, 0), 3);
putText(Show_Frame, "ACC_2", Title_Point + Point(0, button_dis) * 2, FONT_HERSHEY_DUPLEX, 0.5, Scalar(255, 255, 255), 1);
putText(Show_Frame, "ACC_3", Title_Point + Point(0, button_dis) * 3, FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 0, 0), 3);
putText(Show_Frame, "ACC_3", Title_Point + Point(0, button_dis) * 3, FONT_HERSHEY_DUPLEX, 0.5, Scalar(255, 255, 255), 1);
putText(Show_Frame, "ACC_4", Title_Point + Point(0, button_dis) * 4, FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 0, 0), 3);
putText(Show_Frame, "ACC_4", Title_Point + Point(0, button_dis) * 4, FONT_HERSHEY_DUPLEX, 0.5, Scalar(255, 255, 255), 1);
putText(Show_Frame, "ACC_5", Title_Point + Point(0, button_dis) * 5, FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 0, 0), 3);
putText(Show_Frame, "ACC_5", Title_Point + Point(0, button_dis) * 5, FONT_HERSHEY_DUPLEX, 0.5, Scalar(255, 255, 255), 1);
/*//////////////////// +, - Button ////////////////////*/
// - //
rectangle(Show_Frame, Rect(Rectangle_Point_x + Point(-3, -3), Rectangle_Size + Size(6, 6)), Scalar(0, 0, 0), -1);
rectangle(Show_Frame, Rect(Rectangle_Point_x, Rectangle_Size), Scalar(170, 170, 170), -1);
rectangle(Show_Frame, Rect(Rectangle_Point_x + Point(0, button_dis) + Point(-3, -3), Rectangle_Size + Size(6, 6)), Scalar(0, 0, 0), -1);
rectangle(Show_Frame, Rect(Rectangle_Point_x + Point(0, button_dis), Rectangle_Size), Scalar(170, 170, 170), -1);
rectangle(Show_Frame, Rect(Rectangle_Point_x + Point(0, button_dis) * 2 + Point(-3, -3), Rectangle_Size + Size(6, 6)), Scalar(0, 0, 0), -1);
rectangle(Show_Frame, Rect(Rectangle_Point_x + Point(0, button_dis) * 2, Rectangle_Size), Scalar(170, 170, 170), -1);
rectangle(Show_Frame, Rect(Rectangle_Point_x + Point(0, button_dis) * 3 + Point(-3, -3), Rectangle_Size + Size(6, 6)), Scalar(0, 0, 0), -1);
rectangle(Show_Frame, Rect(Rectangle_Point_x + Point(0, button_dis) * 3, Rectangle_Size), Scalar(170, 170, 170), -1);
rectangle(Show_Frame, Rect(Rectangle_Point_x + Point(0, button_dis) * 4 + Point(-3, -3), Rectangle_Size + Size(6, 6)), Scalar(0, 0, 0), -1);
rectangle(Show_Frame, Rect(Rectangle_Point_x + Point(0, button_dis) * 4, Rectangle_Size), Scalar(170, 170, 170), -1);
rectangle(Show_Frame, Rect(Rectangle_Point_x + Point(0, button_dis) * 5 + Point(-3, -3), Rectangle_Size + Size(6, 6)), Scalar(0, 0, 0), -1);
rectangle(Show_Frame, Rect(Rectangle_Point_x + Point(0, button_dis) * 5, Rectangle_Size), Scalar(170, 170, 170), -1);
// + //
rectangle(Show_Frame, Rect(Rectangle_Point_y + Point(-3, -3), Rectangle_Size + Size(6, 6)), Scalar(0, 0, 0), -1);
rectangle(Show_Frame, Rect(Rectangle_Point_y, Rectangle_Size), Scalar(170, 170, 170), -1);
rectangle(Show_Frame, Rect(Rectangle_Point_y + Point(0, button_dis) + Point(-3, -3), Rectangle_Size + Size(6, 6)), Scalar(0, 0, 0), -1);
rectangle(Show_Frame, Rect(Rectangle_Point_y + Point(0, button_dis), Rectangle_Size), Scalar(170, 170, 170), -1);
rectangle(Show_Frame, Rect(Rectangle_Point_y + Point(0, button_dis) * 2 + Point(-3, -3), Rectangle_Size + Size(6, 6)), Scalar(0, 0, 0), -1);
rectangle(Show_Frame, Rect(Rectangle_Point_y + Point(0, button_dis) * 2, Rectangle_Size), Scalar(170, 170, 170), -1);
rectangle(Show_Frame, Rect(Rectangle_Point_y + Point(0, button_dis) * 3 + Point(-3, -3), Rectangle_Size + Size(6, 6)), Scalar(0, 0, 0), -1);
rectangle(Show_Frame, Rect(Rectangle_Point_y + Point(0, button_dis) * 3, Rectangle_Size), Scalar(170, 170, 170), -1);
rectangle(Show_Frame, Rect(Rectangle_Point_y + Point(0, button_dis) * 4 + Point(-3, -3), Rectangle_Size + Size(6, 6)), Scalar(0, 0, 0), -1);
rectangle(Show_Frame, Rect(Rectangle_Point_y + Point(0, button_dis) * 4, Rectangle_Size), Scalar(170, 170, 170), -1);
rectangle(Show_Frame, Rect(Rectangle_Point_y + Point(0, button_dis) * 5 + Point(-3, -3), Rectangle_Size + Size(6, 6)), Scalar(0, 0, 0), -1);
rectangle(Show_Frame, Rect(Rectangle_Point_y + Point(0, button_dis) * 5, Rectangle_Size), Scalar(170, 170, 170), -1);
/*//////////////////// +, - Button Text ////////////////////*/
putText(Show_Frame, "-", Rectangle_Point_x + Point(3, 12), FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 0, 0), 1);
putText(Show_Frame, "-", Rectangle_Point_x + Point(0, button_dis) + Point(3, 12), FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 0, 0), 1);
putText(Show_Frame, "-", Rectangle_Point_x + Point(0, button_dis) * 2 + Point(3, 12), FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 0, 0), 1);
putText(Show_Frame, "-", Rectangle_Point_x + Point(0, button_dis) * 3 + Point(3, 12), FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 0, 0), 1);
putText(Show_Frame, "-", Rectangle_Point_x + Point(0, button_dis) * 4 + Point(3, 12), FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 0, 0), 1);
putText(Show_Frame, "-", Rectangle_Point_x + Point(0, button_dis) * 5 + Point(3, 12), FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 0, 0), 1);
putText(Show_Frame, "+", Rectangle_Point_y + Point(3, 12), FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 0, 0), 1);
putText(Show_Frame, "+", Rectangle_Point_y + Point(0, button_dis) + Point(3, 12), FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 0, 0), 1);
putText(Show_Frame, "+", Rectangle_Point_y + Point(0, button_dis) * 2 + Point(3, 12), FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 0, 0), 1);
putText(Show_Frame, "+", Rectangle_Point_y + Point(0, button_dis) * 3 + Point(3, 12), FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 0, 0), 1);
putText(Show_Frame, "+", Rectangle_Point_y + Point(0, button_dis) * 4 + Point(3, 12), FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 0, 0), 1);
putText(Show_Frame, "+", Rectangle_Point_y + Point(0, button_dis) * 5 + Point(3, 12), FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 0, 0), 1);
//OK Button
rectangle(Show_Frame, Rect(Resolution_Point - Point(-45, -10 - button_dis - button_dis) + Point(-3, -3),
Reset_Button_Size + Size(6, 6)), Scalar(0, 0, 0), -1);
rectangle(Show_Frame, Rect(Resolution_Point - Point(-45, -10 - button_dis - button_dis), Reset_Button_Size), Scalar(170, 170, 170), -1);
putText(Show_Frame, "OK", Resolution_Point - Point(-55, -25 - button_dis - button_dis), FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 0, 0), 1);
//Cancel Button
rectangle(Show_Frame, Rect(Resolution_Point - Point(15, -10 - button_dis - button_dis) + Point(-3, -3),
Reset_Button_Size + Size(6, 6)), Scalar(0, 0, 0), -1);
rectangle(Show_Frame, Rect(Resolution_Point - Point(15, -10 - button_dis - button_dis), Reset_Button_Size), Scalar(170, 170, 170), -1);
putText(Show_Frame, "Cancel", Resolution_Point - Point(17, -25 - button_dis - button_dis), FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 0, 0), 1);
sprintf(Number_of_ROI_S, "%d", Number_of_ROI);
putText(Show_Frame, Number_of_ROI_S, Value_Point, FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 0, 0), 3);
putText(Show_Frame, Number_of_ROI_S, Value_Point, FONT_HERSHEY_DUPLEX, 0.5, Scalar(255, 255, 255), 1);
sprintf(Accuracy_Percent_S, "%d", Accuracy_Percent[0]);
putText(Show_Frame, Accuracy_Percent_S, Value_Point + Point(0, button_dis), FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 0, 0), 3);
putText(Show_Frame, Accuracy_Percent_S, Value_Point + Point(0, button_dis), FONT_HERSHEY_DUPLEX, 0.5, Scalar(255, 255, 255), 1);
if (Accuracy_Percent[1] == 0) sprintf(Accuracy_Percent_S, "X");
else sprintf(Accuracy_Percent_S, "%d", Accuracy_Percent[1]);
putText(Show_Frame, Accuracy_Percent_S, Value_Point + Point(0, button_dis) * 2, FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 0, 0), 3);
putText(Show_Frame, Accuracy_Percent_S, Value_Point + Point(0, button_dis) * 2, FONT_HERSHEY_DUPLEX, 0.5, Scalar(255, 255, 255), 1);
if (Accuracy_Percent[2] == 0) sprintf(Accuracy_Percent_S, "X");
else sprintf(Accuracy_Percent_S, "%d", Accuracy_Percent[2]);
putText(Show_Frame, Accuracy_Percent_S, Value_Point + Point(0, button_dis) * 3, FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 0, 0), 3);
putText(Show_Frame, Accuracy_Percent_S, Value_Point + Point(0, button_dis) * 3, FONT_HERSHEY_DUPLEX, 0.5, Scalar(255, 255, 255), 1);
if (Accuracy_Percent[3] == 0) sprintf(Accuracy_Percent_S, "X");
else sprintf(Accuracy_Percent_S, "%d", Accuracy_Percent[3]);
putText(Show_Frame, Accuracy_Percent_S, Value_Point + Point(0, button_dis) * 4, FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 0, 0), 3);
putText(Show_Frame, Accuracy_Percent_S, Value_Point + Point(0, button_dis) * 4, FONT_HERSHEY_DUPLEX, 0.5, Scalar(255, 255, 255), 1);
if (Accuracy_Percent[4] == 0) sprintf(Accuracy_Percent_S, "X");
else sprintf(Accuracy_Percent_S, "%d", Accuracy_Percent[4]);
putText(Show_Frame, Accuracy_Percent_S, Value_Point + Point(0, button_dis) * 5, FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 0, 0), 3);
putText(Show_Frame, Accuracy_Percent_S, Value_Point + Point(0, button_dis) * 5, FONT_HERSHEY_DUPLEX, 0.5, Scalar(255, 255, 255), 1);
}
void Mouse_Event(int event, int x, int y, int flags, void* userdata) {
if (Setting_Mode_Flag == true && event == EVENT_LBUTTONDOWN) {
if (((Rectangle_Point_x.x <= x) && (Rectangle_Point_x.x + Rectangle_Size.width >= x)) &&
((Rectangle_Point_x.y <= y) && (Rectangle_Point_x.y + Rectangle_Size.height >= y))) { //1-1
Number_of_ROI--;
if (Number_of_ROI == 0) {
Number_of_ROI = 1;
}
if (Number_of_ROI == 4) {
Accuracy_Percent[4] = 0;
}
else if (Number_of_ROI == 3) {
Accuracy_Percent[3] = 0;
Accuracy_Percent[4] = 0;
}
else if (Number_of_ROI == 2) {
Accuracy_Percent[2] = 0;
Accuracy_Percent[3] = 0;
Accuracy_Percent[4] = 0;
}
else if (Number_of_ROI == 1) {
Accuracy_Percent[1] = 0;
Accuracy_Percent[2] = 0;
Accuracy_Percent[3] = 0;
Accuracy_Percent[4] = 0;
}
}
if (((Rectangle_Point_y.x <= x) && (Rectangle_Point_y.x + Rectangle_Size.width >= x)) &&
((Rectangle_Point_y.y <= y) && (Rectangle_Point_y.y + Rectangle_Size.height >= y))) { //1-2
Number_of_ROI++;
if (Number_of_ROI == 6) {
Number_of_ROI = 5;
}
Accuracy_Percent[Number_of_ROI - 1] = 90;
}
if ((Rectangle_Point_x.x <= x) && (Rectangle_Point_x.x + Rectangle_Size.width >= x) &&
((Rectangle_Point_x.y + button_dis <= y) && (Rectangle_Point_x.y + button_dis + Rectangle_Size.height >= y))) { //2-1
if (Accuracy_Percent[0] >= 90) {
Accuracy_Percent[0]--;
}
else {
Accuracy_Percent[0] -= 2;
}
if (Accuracy_Percent[0] == -1 || Accuracy_Percent[0] == -2) {
Accuracy_Percent[0] = 0;
}
}
if (((Rectangle_Point_y.x <= x) && (Rectangle_Point_y.x + Rectangle_Size.width >= x)) &&
((Rectangle_Point_y.y + button_dis <= y) && (Rectangle_Point_y.y + button_dis + Rectangle_Size.height >= y))) { //2-2
if (Accuracy_Percent[0] >= 90) {
Accuracy_Percent[0]++;
}
else {
Accuracy_Percent[0] += 2;
}
if (Accuracy_Percent[0] == 101) {
Accuracy_Percent[0] = 100;
}
}
if ((Rectangle_Point_x.x <= x) && (Rectangle_Point_x.x + Rectangle_Size.width >= x) &&
((Rectangle_Point_x.y + button_dis * 2 <= y) && (Rectangle_Point_x.y + button_dis * 2 + Rectangle_Size.height >= y)) &&
Number_of_ROI > 1) { //3-1
if (Accuracy_Percent[1] >= 90) {
Accuracy_Percent[1]--;
}
else {
Accuracy_Percent[1] -= 2;
}
if (Accuracy_Percent[1] == -1 || Accuracy_Percent[1] == -2) {
Accuracy_Percent[1] = 0;
}
}
if (((Rectangle_Point_y.x <= x) && (Rectangle_Point_y.x + Rectangle_Size.width >= x)) &&
((Rectangle_Point_y.y + button_dis * 2 <= y) && (Rectangle_Point_y.y + button_dis * 2 + Rectangle_Size.height >= y)) &&
Number_of_ROI > 1) { //3-2
if (Accuracy_Percent[1] >= 90) {
Accuracy_Percent[1]++;
}
else {
Accuracy_Percent[1] += 2;
}
if (Accuracy_Percent[1] == 101) {
Accuracy_Percent[1] = 100;
}
}
if ((Rectangle_Point_x.x <= x) && (Rectangle_Point_x.x + Rectangle_Size.width >= x) &&
((Rectangle_Point_x.y + button_dis * 3 <= y) && (Rectangle_Point_x.y + button_dis * 3 + Rectangle_Size.height >= y)) &&
Number_of_ROI > 2) { //4-1
if (Accuracy_Percent[2] >= 90) {
Accuracy_Percent[2]--;
}
else {
Accuracy_Percent[2] -= 2;
}
if (Accuracy_Percent[2] == -1 || Accuracy_Percent[2] == -2) {
Accuracy_Percent[2] = 0;
}
}
if (((Rectangle_Point_y.x <= x) && (Rectangle_Point_y.x + Rectangle_Size.width >= x)) &&
((Rectangle_Point_y.y + button_dis * 3 <= y) && (Rectangle_Point_y.y + button_dis * 3 + Rectangle_Size.height >= y)) &&
Number_of_ROI > 2) { //4-2
if (Accuracy_Percent[2] >= 90) {
Accuracy_Percent[2]++;
}
else {
Accuracy_Percent[2] += 2;
}
if (Accuracy_Percent[2] == 101) {
Accuracy_Percent[2] = 100;
}
}
if ((Rectangle_Point_x.x <= x) && (Rectangle_Point_x.x + Rectangle_Size.width >= x) &&
((Rectangle_Point_x.y + button_dis * 4 <= y) && (Rectangle_Point_x.y + button_dis * 4 + Rectangle_Size.height >= y)) &&
Number_of_ROI > 3) { //5-1
if (Accuracy_Percent[3] >= 90) {
Accuracy_Percent[3]--;
}
else {
Accuracy_Percent[3] -= 2;
}
if (Accuracy_Percent[3] == -1 || Accuracy_Percent[3] == -2) {
Accuracy_Percent[3] = 0;
}
}
if (((Rectangle_Point_y.x <= x) && (Rectangle_Point_y.x + Rectangle_Size.width >= x)) &&
((Rectangle_Point_y.y + button_dis * 4 <= y) && (Rectangle_Point_y.y + button_dis * 4 + Rectangle_Size.height >= y)) &&
Number_of_ROI > 3) { //5-2
if (Accuracy_Percent[3] >= 90) {
Accuracy_Percent[3]++;
}
else {
Accuracy_Percent[3] += 2;
}
if (Accuracy_Percent[3] == 101) {
Accuracy_Percent[3] = 100;
}
}
if ((Rectangle_Point_x.x <= x) && (Rectangle_Point_x.x + Rectangle_Size.width >= x) &&
((Rectangle_Point_x.y + button_dis * 5 <= y) && (Rectangle_Point_x.y + button_dis * 5 + Rectangle_Size.height >= y)) &&
Number_of_ROI > 4) { //6-1
if (Accuracy_Percent[4] >= 90) {
Accuracy_Percent[4]--;
}
else {
Accuracy_Percent[4] -= 2;
}
if (Accuracy_Percent[4] == -1 || Accuracy_Percent[4] == -2) {
Accuracy_Percent[4] = 0;
}
}
if (((Rectangle_Point_y.x <= x) && (Rectangle_Point_y.x + Rectangle_Size.width >= x)) &&
((Rectangle_Point_y.y + button_dis * 5 <= y) && (Rectangle_Point_y.y + button_dis * 5 + Rectangle_Size.height >= y)) &&
Number_of_ROI > 4) { //6-2
if (Accuracy_Percent[4] >= 90) {
Accuracy_Percent[4]++;
}
else {
Accuracy_Percent[4] += 2;
}
if (Accuracy_Percent[4] == 101) {
Accuracy_Percent[4] = 100;
}
}
if (((Resolution_Point.x - 15 <= x) && (Resolution_Point.x - 15 + Reset_Button_Size.width >= x)) &&
((Resolution_Point.y + 10 + button_dis + button_dis <= y) &&
(Resolution_Point.y + 10 + button_dis + button_dis + Reset_Button_Size.height >= y))) { //Cancel_Button
Number_of_ROI = Number_of_ROI_Temp;
Accuracy_Percent[0] = Accuracy_Percent_Temp[0];
Accuracy_Percent[1] = Accuracy_Percent_Temp[1];
Accuracy_Percent[2] = Accuracy_Percent_Temp[2];
Accuracy_Percent[3] = Accuracy_Percent_Temp[3];
Accuracy_Percent[4] = Accuracy_Percent_Temp[4];
Setting_Mode_Flag = !Setting_Mode_Flag;
State_Message_S[7] = "Cancel";
State_Message();
if (Inspect_ROI_Point.size() / 2 == Number_of_ROI) {
State_Message_S[7] = "COMPARING_MODE";
flag = -1;
}
else {
State_Message_S[7] = "Cancel";
flag = 0;
}
}
if (((Resolution_Point.x + 45 <= x) && (Resolution_Point.x + 45 + Reset_Button_Size.width >= x)) &&
((Resolution_Point.y + 10 + button_dis + button_dis <= y) &&
(Resolution_Point.y + 10 + button_dis + button_dis + Reset_Button_Size.height >= y))) { //OK_Button
if (Inspect_ROI_Point.size() / 2 != Number_of_ROI) {
Inspect_ROI_Point.clear();
Standard_ROI.clear();
flag = 0;
}
else if (Number_of_ROI == Number_of_ROI_Temp && (Accuracy_Percent[0] != Accuracy_Percent_Temp[0] || Accuracy_Percent[1] != Accuracy_Percent_Temp[1] ||
Accuracy_Percent[2] != Accuracy_Percent_Temp[2] || Accuracy_Percent[3] != Accuracy_Percent_Temp[3] || Accuracy_Percent[4] != Accuracy_Percent_Temp[4])) {
flag = -1;
}
else if (Number_of_ROI == Number_of_ROI_Temp && (Accuracy_Percent[0] == Accuracy_Percent_Temp[0] && Accuracy_Percent[1] == Accuracy_Percent_Temp[1] &&
Accuracy_Percent[2] == Accuracy_Percent_Temp[2] && Accuracy_Percent[3] == Accuracy_Percent_Temp[3] && Accuracy_Percent[4] == Accuracy_Percent_Temp[4])) {
Inspect_ROI_Point.clear();
Standard_ROI.clear();
flag = 0;
}
FILE* fp_fin = fopen(data_addr, "w");
sprintf(Fput_STR, "%d\n", Number_of_ROI);
fputs(Fput_STR, fp_fin);
for(int j = 0; j < Number_of_ROI; j++){
sprintf(Fput_STR, "%d\n", Accuracy_Percent[j]);
fputs(Fput_STR, fp_fin);
}
for (int i = 0; i < Inspect_ROI_Point.size(); i++) {
sprintf(Fput_STR, "%d\n", Inspect_ROI_Point[i].x);
fputs(Fput_STR, fp_fin);
sprintf(Fput_STR, "%d\n", Inspect_ROI_Point[i].y);
fputs(Fput_STR, fp_fin);
}
fclose(fp_fin);
Setting_Mode_Flag = !Setting_Mode_Flag;
State_Message_S[7] = "OK";
}
}
////ALAM_MARK////
if (((0 <= x) && (113 >= x)) && ((0 <= y) && (30 >= y)) && event == EVENT_LBUTTONDOWN) {
Setting_Mode_Flag = !Setting_Mode_Flag;
Number_of_ROI_Temp = Number_of_ROI;
for(int i = 0; i < 5; i++){
Accuracy_Percent_Temp[i] = Accuracy_Percent[i];
}
if (Setting_Mode_Flag == false) {
if (Inspect_ROI_Point.size() / 2 == Number_of_ROI) {
State_Message_S[7] = "COMPARING_MODE";
flag = -1;
}
else {
State_Message_S[7] = "POINT_CLICK";
flag = 0;
}
}
else {
State_Message_S[7] = "SETTING_MODE";
flag = 3;
}
}
if (event == EVENT_LBUTTONDOWN && (flag == 0 || flag == 1)) {
temp = Point(x, y);
Inspect_ROI_Point.push_back(temp);
State_Message_S[7] = "POINT_CLICK";
flag++;
}
if (flags == EVENT_FLAG_LBUTTON && event == EVENT_MOUSEMOVE && flag == 1) {
rectangle(Show_Frame, Rect(temp, Point(x, y)), Scalar(0, 0, 255), 1);
imshow("Show_Frame", Show_Frame);
}
if (event == EVENT_LBUTTONUP && flag == 1) {
temp2 = Point(x, y);
if (temp2 != temp) {
Inspect_ROI_Point.push_back(temp2);
flag++;
}
else if (temp2 == temp) {
Inspect_ROI_Point.clear();
flag = 0;
}
if (flag == 2) {
if (Inspect_ROI_Point.size() / 2 == Number_of_ROI) {
for (int i = 0; i < Inspect_ROI_Point.size(); i += 2) {
Standard_ROI.push_back(Mat(frame, Rect(Point(Inspect_ROI_Point[i]),
Point(Inspect_ROI_Point[i + 1]))).clone());
}
FILE* fp_fin = fopen(data_addr, "w");
sprintf(Fput_STR, "%d\n", Number_of_ROI);
fputs(Fput_STR, fp_fin);
for(int j = 0; j < Number_of_ROI; j++){
sprintf(Fput_STR, "%d\n", Accuracy_Percent[j]);
fputs(Fput_STR, fp_fin);
}
for (int i = 0; i < Inspect_ROI_Point.size(); i++) {
sprintf(Fput_STR, "%d\n", Inspect_ROI_Point[i].x);
fputs(Fput_STR, fp_fin);
sprintf(Fput_STR, "%d\n", Inspect_ROI_Point[i].y);
fputs(Fput_STR, fp_fin);
}
fclose(fp_fin);
for (int x = 1; x < Standard_ROI.size() + 1; x++) {
char Write_Name[100];
sprintf(Write_Name, "%sROI_NUM_%d.PNG", img_data_addr, x);
imwrite(Write_Name, Standard_ROI[x - 1]);
}
flag = -1;
}
else {
flag = 0;
}
}
}
}
int main() {
cap = VideoCapture(WEB_CAM); //WEB_CAM, TEST_VIDEO_1920P
if (!cap.isOpened()) {
cout << "Could not find or open Video" << endl;
return -1;
}
if (wiringPiSetupGpio() == -1) {
cout << "Could Not find or open wiringPi" << endl;
return -1;
}
pinMode(INPUT_DATA_RESET, INPUT);
pinMode(INPUT_PORT, INPUT);
for (int i = 0; i < sizeof(Led); i++) {
pinMode(Led[i], OUTPUT);
digitalWrite(Led[i], 0);
}
namedWindow("Show_Frame", WINDOW_FULLSCREEN);
setMouseCallback("Show_Frame", Mouse_Event);
cap.set(3, 640);
cap.set(4, 480);
width = 640;
height = 480;
for (int i = 0; i < 20; i++) {
cap >> frame;
imshow("Show_Frame", frame);
waitKey(1);
}
cout << width << endl;
cout << height << endl;
State_Message_Point.clear();
State_Message_Point.push_back(Point(15, height - 125));
State_Message_Point.push_back(Point(15, height - 110));
State_Message_Point.push_back(Point(15, height - 95));
State_Message_Point.push_back(Point(15, height - 80));
State_Message_Point.push_back(Point(15, height - 65));
State_Message_Point.push_back(Point(15, height - 50));
State_Message_Point.push_back(Point(15, height - 35));
State_Message_Point.push_back(Point(15, height - 20));
State_Message_S.push_back(String(" "));
State_Message_S.push_back(String(" "));
State_Message_S.push_back(String(" "));
State_Message_S.push_back(String(" "));
State_Message_S.push_back(String(" "));
State_Message_S.push_back(String(" "));
State_Message_S.push_back(String(" "));
State_Message_S.push_back(String(" "));
State_Message_S[7] = "Res : 640x480";
Accuracy_Percent[0] = 90;
Accuracy_Percent[1] = 0;
Accuracy_Percent[2] = 0;
Accuracy_Percent[3] = 0;
Accuracy_Percent[4] = 0;
FILE* total_file = fopen(total_data_addr, "r");
if (total_file != NULL) {
char line[10];
fgets(line, sizeof(line), total_file);
Compare_Total = atoi(line);
fclose(total_file);
}
FILE* good_file = fopen(good_data_addr, "r");
if (good_file != NULL) {
char line[10];
fgets(line, sizeof(line), good_file);
Compare_Good = atoi(line);
fclose(good_file);
}
FILE* bad_file = fopen(bad_data_addr, "r");
if (bad_file != NULL) {
char line[10];
fgets(line, sizeof(line), bad_file);
Compare_Bad = atoi(line);
fclose(bad_file);
}
vector<unsigned int> Config_Data;
FILE* fp = fopen(data_addr, "r");
if (fp != NULL) {
char line[255];
while (fgets(line, sizeof(line), fp) != NULL) {
Config_Data.push_back(atoi(line));
}
if (Config_Data.size() >= 1) {
Number_of_ROI = Config_Data[0];
}
if (Config_Data.size() >= 2) {
for(int i = 1; i < Number_of_ROI + 1; i++){
Accuracy_Percent[i - 1] = Config_Data[i];
}
}
if (Config_Data.size() >= Number_of_ROI + 1) {
if ((Config_Data.size() - Number_of_ROI + 1) / 4 == Number_of_ROI) {
for (int i = Number_of_ROI + 1; i < Config_Data.size(); i += 2) {
Point temp_pt = Point(Config_Data[i], Config_Data[i + 1]);
Inspect_ROI_Point.push_back(temp_pt);
}
for (int i = 1; i < Number_of_ROI + 1; i++) {
char Fread_Path[100];
sprintf(Fread_Path, "%sROI_NUM_%d.PNG", img_data_addr, i);
Mat ROI_Image = imread(Fread_Path);
Standard_ROI.push_back(ROI_Image);
}
flag = -1;
}
}
fclose(fp);
}
digitalWrite(Led[0], 1);
int key = 0;
clock_t start, end;
bool reset_signal = false;
while (1) {
start_signal = !digitalRead(INPUT_PORT);
if (start_signal == true) {
delay(50);
start_signal = !digitalRead(INPUT_PORT);
if (start_signal == true)
digitalWrite(Led[0], 0);
}
else {
digitalWrite(Led[0], 1);
digitalWrite(Led[1], 0);
digitalWrite(Led[2], 0);
}
reset_signal = digitalRead(INPUT_DATA_RESET);
if (start_signal == false) {
delay(50);
reset_signal = digitalRead(INPUT_DATA_RESET);
if (reset_signal == false) {
Compare_Total = 0;
Compare_Good = 0;
Compare_Bad = 0;
FILE* total_file = fopen(total_data_addr, "w");
sprintf(Fput_STR, "%d\n", Compare_Total);
fputs(Fput_STR, total_file);
fclose(total_file);
FILE* good_file = fopen(bad_data_addr, "w");
sprintf(Fput_STR, "%d\n", Compare_Bad);
fputs(Fput_STR, good_file);
fclose(good_file);
FILE* bad_file = fopen(good_data_addr, "w");
sprintf(Fput_STR, "%d\n", Compare_Good);
fputs(Fput_STR, bad_file);
fclose(bad_file);
}
}
start = clock();
cap >> frame;
if (frame.empty())
break;
Show_Frame = frame.clone();
//GaussianBlur(frame, frame, Size(37, 37), 0);
Compare_State(Scalar(0, 255, 255));
if (Config_Flag == true) {
for (int i = 0; i < Inspect_ROI_Point.size(); i += 2) {
Standard_ROI.push_back(Mat(frame, Rect(Point(Inspect_ROI_Point[i]),
Point(Inspect_ROI_Point[i + 1]))).clone());
}
Config_Flag = false;
}
if (flag == 1) {
circle(Show_Frame, temp, 2, Scalar(0, 0, 255), -1);
char show_state_run[10] = "[SET]";
putText(Show_Frame, show_state_run, Point(width / 2, 25) + Point(-120, -2), FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 0, 0), 4);
putText(Show_Frame, show_state_run, Point(width / 2, 25) + Point(-120, -2), FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 0, 255), 1);
}
else if (flag == -1 && start_signal == true) {
double result;
double maxv;
char maxv_S[11];
char result_S[10];
unsigned char Standard_ROI_Count = 0;
bool Compare_Flag = true;
for (int i = 0; i < Inspect_ROI_Point.size(); i += 2) {
Inspect_ROI = Mat(frame, Rect(Point(Inspect_ROI_Point[i]), Point(Inspect_ROI_Point[i + 1])));
Mat Inspect_ROI_blur;
Mat Standard_ROI_blur;
blur(Inspect_ROI, Inspect_ROI_blur, Size(9, 9));
blur(Standard_ROI[Standard_ROI_Count], Standard_ROI_blur, Size(9, 9));
double Blue = 0, Green = 0, Red = 0, total_value = 0, total_pixel;
double std_Blue = 0, std_Green = 0, std_Red = 0, std_total_value = 0;
total_pixel = Inspect_ROI_blur.cols * Inspect_ROI_blur.rows;
for (int i = 0; i < Inspect_ROI_blur.rows; i++) {
for (int j = 0; j < Inspect_ROI_blur.cols; j++) {
Blue += (int)Inspect_ROI_blur.at<Vec3b>(i, j)[0];
Green += (int)Inspect_ROI_blur.at<Vec3b>(i, j)[1];
Red += (int)Inspect_ROI_blur.at<Vec3b>(i, j)[2];
}
}
for (int x = 0; x < Standard_ROI_blur.rows; x++) {
for (int y = 0; y < Standard_ROI_blur.cols; y++) {
std_Blue += (int)Standard_ROI_blur.at<Vec3b>(x, y)[0];
std_Green += (int)Standard_ROI_blur.at<Vec3b>(x, y)[1];
std_Red += (int)Standard_ROI_blur.at<Vec3b>(x, y)[2];
}
}
unsigned int dis_Blue = fabs(Blue - std_Blue);
unsigned int dis_Green = fabs(Green - std_Green);
unsigned int dis_Red = fabs(Red - std_Red);
//Comparision color wight Blue 50%, Green 25%, Red 25%, Because yellow is for sensitive reaction to colors.
double Blue_Percentage = (double)dis_Blue / std_Blue * 50;
double Green_Percentage = (double)dis_Green / std_Green * 25;
double Red_Percentage = (double)dis_Red / std_Red * 25;
maxv = Blue_Percentage + Green_Percentage + Blue_Percentage;
maxv = 100 - maxv;
sprintf(maxv_S, "%d : %.2f", Standard_ROI_Count, maxv);
State_Message_S[7] = maxv_S;
State_Message();
if (maxv < Accuracy_Percent[Standard_ROI_Count]) {
Compare_Flag = false;
}
Standard_ROI_Count++;
}
end = clock();
result = (double)(end - start);
sprintf(result_S, "%.2fms", result / CLOCKS_PER_SEC);
State_Message_S[7] = result_S;
Compare_Total++;
FILE* total_file = fopen(total_data_addr, "w");
sprintf(Fput_STR, "%d\n", Compare_Total);
fputs(Fput_STR, total_file);
fclose(total_file);
if (Compare_Flag == false) {
Compare_Bad++;
Compare_State(Scalar(0, 0, 255));
FILE* fp_fin = fopen(bad_data_addr, "w");
sprintf(Fput_STR, "%d\n", Compare_Bad);
fputs(Fput_STR, fp_fin);
fclose(fp_fin);
digitalWrite(Led[2], 1);
}
else {
Compare_Good++;
Compare_State(Scalar(0, 255, 0));
FILE* fp_fin = fopen(good_data_addr, "w");
sprintf(Fput_STR, "%d\n", Compare_Good);
fputs(Fput_STR, fp_fin);
fclose(fp_fin);
digitalWrite(Led[1], 1);
}
Compare_Flag = true;
int num = 1;
for (int i = 0; i < Inspect_ROI_Point.size(); i += 2) {
char num_str[2];
sprintf(num_str, "%d", num);
putText(Show_Frame, num_str, Inspect_ROI_Point[i] - Point(5, 3), FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 0, 255), 0.5);
rectangle(Show_Frame, Rect(Point(Inspect_ROI_Point[i]),
Point(Inspect_ROI_Point[i + 1])), Scalar(0, 0, 255), 1);
num++;
}
char show_state_run[10] = "[RUN]";
putText(Show_Frame, show_state_run, Point(width / 2, 25) + Point(-120, -2), FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 0, 0), 4);
putText(Show_Frame, show_state_run, Point(width / 2, 25) + Point(-120, -2), FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 255, 0), 1);
start_signal = !digitalRead(INPUT_PORT);
while (start_signal) {
start_signal = !digitalRead(INPUT_PORT);
}
}
else if (flag == -1) {
int num = 1;
for (int i = 0; i < Inspect_ROI_Point.size(); i += 2) {
char num_str[2];
sprintf(num_str, "%d", num);
putText(Show_Frame, num_str, Inspect_ROI_Point[i] - Point(5, 3), FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 0, 255), 0.5);
rectangle(Show_Frame, Rect(Point(Inspect_ROI_Point[i]),
Point(Inspect_ROI_Point[i + 1])), Scalar(0, 0, 255), 1);
num++;
}
char show_state_run[10] = "[RUN]";
putText(Show_Frame, show_state_run, Point(width / 2, 25) + Point(-120, -2), FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 0, 0), 4);
putText(Show_Frame, show_state_run, Point(width / 2, 25) + Point(-120, -2), FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 255, 0), 1);
}
else if (flag == 3 && Setting_Mode_Flag == true) {
Setting_Mode();
char show_state_run[10] = "[SET]";
putText(Show_Frame, show_state_run, Point(width / 2, 25) + Point(-120, -2), FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 0, 0), 4);
putText(Show_Frame, show_state_run, Point(width / 2, 25) + Point(-120, -2), FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 0, 255), 1);
}
else if (flag == 0) {
int num = 1;
for (int i = 0; i < Inspect_ROI_Point.size(); i += 2) {
char num_str[2];
sprintf(num_str, "%d", num);
putText(Show_Frame, num_str, Inspect_ROI_Point[i] - Point(5, 3), FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 0, 255), 0.5);
rectangle(Show_Frame, Rect(Point(Inspect_ROI_Point[i]),
Point(Inspect_ROI_Point[i + 1])), Scalar(0, 0, 255), 1);
num++;
}
char show_state_run[10] = "[SET]";
putText(Show_Frame, show_state_run, Point(width / 2, 25) + Point(-120, -2), FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 0, 0), 4);
putText(Show_Frame, show_state_run, Point(width / 2, 25) + Point(-120, -2), FONT_HERSHEY_DUPLEX, 0.5, Scalar(0, 0, 255), 1);
}
State_Message();
Center_Marking(width, height);
ALAM_Marking();
Compare_Result();
imshow("Show_Frame", Show_Frame);
key = waitKey(33);
if (key == 27) {
flag = 99;
break;
}
}
for (int i = 0; i < sizeof(Led); i++) {
pinMode(Led[i], OUTPUT);
digitalWrite(Led[i], 0);
}
return 0;
}
'CELLON Vision > Source Code' 카테고리의 다른 글
CELLON I 시료 걸쇠 Sobel 추출 UI 적용 데모(20230323) (0) | 2023.03.23 |
---|---|
CELLON 2023_03_12 (LAN 통신 제외한 최종 투입) Aging_Code (0) | 2023.03.12 |
CELLON 2023_03_09(Yellow_Result, UI Updates) (0) | 2023.03.09 |
CELLON(투입) - 이후 변경 (0) | 2023.02.13 |
CELLON CompareHist Test Source.cpp, Hist_Plot.py (0) | 2022.12.18 |