-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
140 additions
and
7 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+79.4 MB
Learning_OpenCV/.vs/Learning_OpenCV/v17/ipch/AutoPCH/2e189cb4c51687e1/PROJETO1.ipch
Binary file not shown.
Binary file added
BIN
+79.4 MB
...OpenCV/.vs/Learning_OpenCV/v17/ipch/AutoPCH/d3b8ece7d0d1f79/COLORPICKER(PROJECT1AUX).ipch
Binary file not shown.
39 changes: 39 additions & 0 deletions
39
Learning_OpenCV/Learning_OpenCV/ColorPicker(Project1Aux).cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include <opencv2/imgcodecs.hpp> | ||
#include <opencv2/highgui.hpp> | ||
#include <opencv2/imgproc.hpp> | ||
#include <iostream> | ||
|
||
using namespace std; | ||
using namespace cv; | ||
|
||
int main() { | ||
VideoCapture cam(0); | ||
Mat img,imgHSV, mask; | ||
int hmin = 0, smin = 0, vmin = 0; | ||
int hmax = 0, smax = 0, vmax = 0; | ||
|
||
namedWindow("Track Bars", (640, 320)); | ||
createTrackbar("Hue Min", "Track Bars", &hmin, 179); //Range do HUE é 0-180 | ||
createTrackbar("Hue Max", "Track Bars", &hmax, 179); | ||
createTrackbar("Sat Min", "Track Bars", &smin, 255); | ||
createTrackbar("Sat Max", "Track Bars", &smax, 255); | ||
createTrackbar("Val Min", "Track Bars", &vmin, 255); | ||
createTrackbar("Val Max", "Track Bars", &vmax, 255); | ||
|
||
while (1) { | ||
cam.read(img); | ||
|
||
cvtColor(img, imgHSV, COLOR_BGR2HSV); | ||
|
||
Scalar lowerLimit(hmin, smin, vmin), upperLimit(hmax, smax, vmax); | ||
inRange(imgHSV, lowerLimit, upperLimit, mask); | ||
|
||
cout << hmin << ", " << smin << ", " << vmin << ", "; | ||
cout << hmax << ", " << smax << ", " << vmax << endl; | ||
|
||
imshow("Image Mask", mask); | ||
imshow("Image", img); | ||
waitKey(1); | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#include <opencv2/imgcodecs.hpp> | ||
#include <opencv2/highgui.hpp> | ||
#include <opencv2/imgproc.hpp> | ||
#include <iostream> | ||
|
||
using namespace std; | ||
using namespace cv; | ||
|
||
Mat img; | ||
|
||
vector<vector<int>> newPoints; | ||
vector<vector<int>> Colors{//Conjunto de cores detectáveis (HSVmin, HSVmax) | ||
{124, 24, 0, 141, 156, 255},//Roxo | ||
{100, 88, 82, 127, 226, 189},//Azul Claro | ||
{99, 94, 3, 127, 187, 167},//Azul Escuro | ||
{43, 104, 149, 67, 191, 255},//Verde | ||
{12, 139, 168, 27, 226, 255},//Laranja | ||
{24, 80, 123, 41, 149, 248},//Amarelo | ||
{0, 147, 56, 9, 255, 175} //Vinho | ||
}; | ||
vector<Scalar> ColorValues{{255,30,255},{255,100,100},{255,10,10},{0,255,0},{0,100,255},{0,255,255},{0,0,255}}; | ||
vector<string> ColorNames{ {"Roxo"},{"Azul Claro"},{"Azul Escuro"},{"Verde"},{"Laranja"},{"Amarelo"},{"Vinho"}}; | ||
|
||
Point getContours(Mat imgDil) { //Segunda imagem é a image que será desenhada | ||
vector<vector<Point>> contours; | ||
vector<Vec4i> hierarchy; | ||
|
||
findContours(imgDil, contours, hierarchy, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE); | ||
//drawContours(img, contours, -1, Scalar(0, 0, 0), 3); | ||
|
||
vector<vector<Point>> conPoly(contours.size()); //Arestas do contorno | ||
vector<Rect> boundRect(contours.size()); //Vetor de retângulos, irá armazenar os retângulos; | ||
Point centerPoint(0, 0); | ||
//Filtros | ||
for (int i = 0; i < contours.size(); i++) { | ||
int area = contourArea(contours[i]); | ||
cout << area << endl; | ||
|
||
|
||
if (area > 1000) { | ||
float peri = arcLength(contours[i], true);//pegando o perímetro do contorno [i], e se ele é fechado ou năo | ||
approxPolyDP(contours[i], conPoly[i], 0.02 * peri, true); | ||
boundRect[i] = boundingRect(conPoly[i]); | ||
centerPoint.x = boundRect[i].x + boundRect[i].width / 2; | ||
centerPoint.y = boundRect[i].y; | ||
//drawContours(img, conPoly, i, Scalar(255, 30, 255), 3); | ||
//rectangle(img, boundRect[i].tl(), boundRect[i].br(), Scalar(255, 0, 0), 5); | ||
} | ||
} | ||
return centerPoint; | ||
} | ||
|
||
vector<vector<int>> findColor(Mat img) { | ||
Mat imgHSV; | ||
cvtColor(img, imgHSV, COLOR_BGR2HSV); | ||
|
||
for (int i=0; i < Colors.size(); i++) { | ||
Scalar lowerLimit(Colors[i][0], Colors[i][1], Colors[i][2]); //i indica a cor, neste caso | ||
Scalar upperLimit(Colors[i][3], Colors[i][4], Colors[i][5]); | ||
Mat mask; | ||
inRange(imgHSV, lowerLimit, upperLimit, mask); | ||
//imshow(ColorNames[i], mask); | ||
Point centerPoint = getContours(mask); | ||
|
||
if (centerPoint.x != 0 && centerPoint.y != 0) { | ||
newPoints.push_back({ centerPoint.x , centerPoint.y , i }); | ||
} | ||
} | ||
return newPoints; | ||
} | ||
|
||
void Draw(vector<vector<int>> newPoints, vector<Scalar> ColorValues) { | ||
for (int i = 0; i < newPoints.size(); i++) { | ||
circle(img, Point(newPoints[i][0], newPoints[i][1]), 10, ColorValues[newPoints[i][2]], FILLED); | ||
} | ||
} | ||
|
||
int main() { | ||
VideoCapture cap(0); | ||
|
||
|
||
while (1) { | ||
cap.read(img); | ||
|
||
newPoints = findColor(img); | ||
Draw(newPoints, ColorValues); | ||
|
||
imshow("Image", img); | ||
waitKey(1); | ||
} | ||
return 0; | ||
} |
Binary file added
BIN
+258 KB
Learning_OpenCV/Learning_OpenCV/x64/Debug/ColorPicker(Project1Aux).obj
Binary file not shown.
Binary file modified
BIN
+77.1 KB
(110%)
Learning_OpenCV/Learning_OpenCV/x64/Debug/Learning_OpenCV.ilk
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
FaceDetection.cpp | ||
Projeto1.cpp | ||
D:\Documentos\Universidade\Codes\How_to_Code\Learning_OpenCV\Learning_OpenCV\Projeto1.cpp(36,12): warning C4244: 'inicializando': conversão de 'double' para 'int', possível perda de dados | ||
D:\Documentos\Universidade\Codes\How_to_Code\Learning_OpenCV\Learning_OpenCV\Projeto1.cpp(41,15): warning C4244: 'inicializando': conversão de 'double' para 'float', possível perda de dados | ||
Learning_OpenCV.vcxproj -> D:\Documentos\Universidade\Codes\How_to_Code\Learning_OpenCV\x64\Debug\Learning_OpenCV.exe |
Binary file modified
BIN
+1.78 KB
(120%)
Learning_OpenCV/Learning_OpenCV/x64/Debug/Learning_OpenCV.tlog/CL.command.1.tlog
Binary file not shown.
Binary file modified
BIN
+56.2 KB
(120%)
Learning_OpenCV/Learning_OpenCV/x64/Debug/Learning_OpenCV.tlog/CL.read.1.tlog
Binary file not shown.
Binary file modified
BIN
+1.58 KB
(130%)
Learning_OpenCV/Learning_OpenCV/x64/Debug/Learning_OpenCV.tlog/CL.write.1.tlog
Binary file not shown.
Binary file modified
BIN
-20 Bytes
(99%)
Learning_OpenCV/Learning_OpenCV/x64/Debug/Learning_OpenCV.tlog/link.command.1.tlog
Binary file not shown.
Binary file modified
BIN
+200 Bytes
(110%)
Learning_OpenCV/Learning_OpenCV/x64/Debug/Learning_OpenCV.tlog/link.read.1.tlog
Binary file not shown.
Binary file modified
BIN
-10 Bytes
(99%)
Learning_OpenCV/Learning_OpenCV/x64/Debug/Learning_OpenCV.tlog/link.write.1.tlog
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.