diff --git a/ora5/proj1/filtered_stud.png b/ora5/proj1/filtered_stud.png new file mode 100644 index 0000000..7c35c5c Binary files /dev/null and b/ora5/proj1/filtered_stud.png differ diff --git a/ora5/proj1/gray_stud.png b/ora5/proj1/gray_stud.png new file mode 100644 index 0000000..4ca80b2 Binary files /dev/null and b/ora5/proj1/gray_stud.png differ diff --git a/ora5/proj1/histo.o b/ora5/proj1/histo.o new file mode 100644 index 0000000..fceefea Binary files /dev/null and b/ora5/proj1/histo.o differ diff --git a/ora5/proj1/m2 b/ora5/proj1/m2 new file mode 100644 index 0000000..edb986a --- /dev/null +++ b/ora5/proj1/m2 @@ -0,0 +1,45 @@ +#include "histo.h" +#include +#include +#include +#include +#include + +using namespace cv; + +int main(){ + Mat img = imread("../madar.jpg", IMREAD_COLOR); + imshow("img", img); + + Histo::showHisto(img, "histo", 1); + + std::vector chs; + split(img, chs); + + /*imshow("r", chs[2]); + imshow("g", chs[1]); + imshow("b", chs[0]);*/ + + + Mat dest1, dest2, dest3, dest4, mask; + + //dest1 = img > 100; + //threshold(img, dest2, 100, 255, THRESH_BINARY); + //threshold(img, dest3, 100, 255, THRESH_OTSU); + //threshold(img, dest4, 100, 255, THRESH_TRIANGLE); + + //medianBlur(dest1, dest1, 3); + + threshold(chs[0], mask, 120, 255, THRESH_BINARY|cv::THRESH_OTSU); + + img.copyTo(dest2, mask); + + + //imshow("dest1", dest1); + imshow("dest2", dest2); + //imshow("dest3", dest3); + //imshow("dest4", dest4); + + while(waitKey(3) != 'q'); + return 0; +} diff --git a/ora5/proj1/main b/ora5/proj1/main new file mode 100755 index 0000000..c787184 Binary files /dev/null and b/ora5/proj1/main differ diff --git a/ora5/proj1/main.cpp b/ora5/proj1/main.cpp index edb986a..36f31f3 100644 --- a/ora5/proj1/main.cpp +++ b/ora5/proj1/main.cpp @@ -1,45 +1,75 @@ -#include "histo.h" +#include +#include #include #include #include -#include -#include +using namespace std; using namespace cv; -int main(){ - Mat img = imread("../madar.jpg", IMREAD_COLOR); - imshow("img", img); +void kordetektalo1(const Mat& gray, vector& circles) { - Histo::showHisto(img, "histo", 1); - - std::vector chs; - split(img, chs); - - /*imshow("r", chs[2]); - imshow("g", chs[1]); - imshow("b", chs[0]);*/ - - - Mat dest1, dest2, dest3, dest4, mask; - - //dest1 = img > 100; - //threshold(img, dest2, 100, 255, THRESH_BINARY); - //threshold(img, dest3, 100, 255, THRESH_OTSU); - //threshold(img, dest4, 100, 255, THRESH_TRIANGLE); - - //medianBlur(dest1, dest1, 3); - - threshold(chs[0], mask, 120, 255, THRESH_BINARY|cv::THRESH_OTSU); - - img.copyTo(dest2, mask); - - - //imshow("dest1", dest1); - imshow("dest2", dest2); - //imshow("dest3", dest3); - //imshow("dest4", dest4); - - while(waitKey(3) != 'q'); - return 0; + int cannyTh = 60; + int minPoints = 30; + int minR = 22; //K1: allitsd be + int maxR = 26; //K1: allitsd be + int d = 2; + int minDist = 10; + + cv::HoughCircles(gray, circles, cv::HOUGH_GRADIENT, d, minDist, cannyTh, minPoints, minR, maxR); +} + +int main(){ + Mat img = imread("past.jpg", IMREAD_COLOR); + if(img.empty()){ + return 1; + } + + // 1. Konvertáld szürkeskálássá az img képet + Mat gray; + cvtColor(img, gray, COLOR_BGR2GRAY); + imwrite("gray_stud.png", gray); + + + vector circles; + kordetektalo1(gray, circles); + + // 2. Végezz mediánszűrés 11x11-es ablakmérettel. + Mat mb2; + medianBlur(img, mb2, 11); + imwrite("filtered_stud.png", mb2); + + // 3. rajzold ki a detektált köröket az eredeti képre + // sugár: 6, szín: tiszta piros, vonalvastagság: FILLED + int radius = 6; + + for (auto c : circles) { + int x = c[0]; + int y = c[1]; + circle(img, Point(x,y), radius, Scalar(0, 100, 100), 2, cv::LineTypes::FILLED); + } + + imwrite("result_stud.png", img); + + + // 4. Határozd meg a körök középpontja alá eső pixelek + // KÉK komponensének átlagát a SZŰRT képen. + double mean_v = 0; + vector chs; + split(circles, chs); //bgr + int count = 0; + for(auto c : circles){ + int x = c[0]; + int y = c[1]; + mean_v += img.at(y,x); + } + mean_v /= circles.size(); + + + // Jelenitsd meg az atlagot a standard kimeneten. + // cout << mean_v << endl; + + waitKey(); + + return 0; } diff --git a/ora5/proj1/main.o b/ora5/proj1/main.o new file mode 100644 index 0000000..912e397 Binary files /dev/null and b/ora5/proj1/main.o differ diff --git a/ora5/proj1/past.jpg b/ora5/proj1/past.jpg new file mode 100644 index 0000000..ce04d25 Binary files /dev/null and b/ora5/proj1/past.jpg differ diff --git a/ora5/proj1/result_stud.png b/ora5/proj1/result_stud.png new file mode 100644 index 0000000..566da7d Binary files /dev/null and b/ora5/proj1/result_stud.png differ diff --git a/ora7/.clangd b/ora7/.clangd new file mode 100644 index 0000000..5f1474c --- /dev/null +++ b/ora7/.clangd @@ -0,0 +1,2 @@ +CompileFlags: + Add: [-I/usr/include/opencv4, -std=c++17] diff --git a/ora7/Képek (kontúrkezelés)-20251120.zip b/ora7/Képek (kontúrkezelés)-20251120.zip new file mode 100644 index 0000000..9fd6442 Binary files /dev/null and b/ora7/Képek (kontúrkezelés)-20251120.zip differ diff --git a/ora7/Makefile b/ora7/Makefile new file mode 100644 index 0000000..a350518 --- /dev/null +++ b/ora7/Makefile @@ -0,0 +1,18 @@ +CXX = g++ +CXXFLAGS = -Wall -O2 `pkg-config --cflags opencv4` +LIBS = `pkg-config --libs opencv4` + +SRC = $(wildcard *.cpp) +OBJ = $(SRC:.cpp=.o) +TARGET = main + +all: $(TARGET) + +$(TARGET): $(OBJ) + $(CXX) $(OBJ) -o $@ $(LIBS) + +%.o: %.cpp + $(CXX) $(CXXFLAGS) -c $< -o $@ + +clean: + rm -f $(OBJ) $(TARGET) diff --git a/ora7/dog.jpg b/ora7/dog.jpg new file mode 100644 index 0000000..fc2eb76 Binary files /dev/null and b/ora7/dog.jpg differ diff --git a/ora7/form.png b/ora7/form.png new file mode 100644 index 0000000..297ce4e Binary files /dev/null and b/ora7/form.png differ diff --git a/ora7/gumialatet3.jpg b/ora7/gumialatet3.jpg new file mode 100644 index 0000000..104037f Binary files /dev/null and b/ora7/gumialatet3.jpg differ diff --git a/ora7/kincseslada.png b/ora7/kincseslada.png new file mode 100644 index 0000000..609f56c Binary files /dev/null and b/ora7/kincseslada.png differ diff --git a/ora7/ko.png b/ora7/ko.png new file mode 100644 index 0000000..548dfc8 Binary files /dev/null and b/ora7/ko.png differ diff --git a/ora7/leaves.jpg b/ora7/leaves.jpg new file mode 100644 index 0000000..a1f50d4 Binary files /dev/null and b/ora7/leaves.jpg differ diff --git a/ora7/main.cpp b/ora7/main.cpp new file mode 100644 index 0000000..d20cd44 --- /dev/null +++ b/ora7/main.cpp @@ -0,0 +1,26 @@ +#include "histo.h" +#include +#include +#include +#include + +using namespace cv; + +int main(){ + Mat img = imread("dark_img.jpg", IMREAD_GRAYSCALE); + imshow("img", img); + Histo::showHisto(img); + + double ah, fh; + minMaxLoc(img, &ah, &fh); + + fh = 30; + + Mat dest = (ah == fh) ? img.clone() : (img-ah) * 255 / (fh-ah); + + imshow("dest", dest); + Histo::showHisto(dest, "eredmeny"); + + waitKey(); + return 0; +} diff --git a/ora7/objects_prop.png b/ora7/objects_prop.png new file mode 100644 index 0000000..5dd6990 Binary files /dev/null and b/ora7/objects_prop.png differ diff --git a/ora7/objects_prop1.png b/ora7/objects_prop1.png new file mode 100644 index 0000000..348c966 Binary files /dev/null and b/ora7/objects_prop1.png differ diff --git a/ora7/objektumok.png b/ora7/objektumok.png new file mode 100644 index 0000000..b94c2d2 Binary files /dev/null and b/ora7/objektumok.png differ diff --git a/ora7/ollo.png b/ora7/ollo.png new file mode 100644 index 0000000..7f59bba Binary files /dev/null and b/ora7/ollo.png differ diff --git a/ora7/perecek.zip b/ora7/perecek.zip new file mode 100644 index 0000000..6bf68a9 Binary files /dev/null and b/ora7/perecek.zip differ diff --git a/ora7/perecek/1.png b/ora7/perecek/1.png new file mode 100644 index 0000000..db24211 Binary files /dev/null and b/ora7/perecek/1.png differ diff --git a/ora7/perecek/2.png b/ora7/perecek/2.png new file mode 100644 index 0000000..c8126cd Binary files /dev/null and b/ora7/perecek/2.png differ diff --git a/ora7/perecek/3.png b/ora7/perecek/3.png new file mode 100644 index 0000000..74f4074 Binary files /dev/null and b/ora7/perecek/3.png differ diff --git a/ora7/perecek/4.png b/ora7/perecek/4.png new file mode 100644 index 0000000..dd8f71f Binary files /dev/null and b/ora7/perecek/4.png differ diff --git a/ora7/pretzel.png b/ora7/pretzel.png new file mode 100644 index 0000000..a84da90 Binary files /dev/null and b/ora7/pretzel.png differ diff --git a/ora7/proj1/.clangd b/ora7/proj1/.clangd new file mode 100644 index 0000000..5f1474c --- /dev/null +++ b/ora7/proj1/.clangd @@ -0,0 +1,2 @@ +CompileFlags: + Add: [-I/usr/include/opencv4, -std=c++17] diff --git a/ora7/proj1/Makefile b/ora7/proj1/Makefile new file mode 100644 index 0000000..a350518 --- /dev/null +++ b/ora7/proj1/Makefile @@ -0,0 +1,18 @@ +CXX = g++ +CXXFLAGS = -Wall -O2 `pkg-config --cflags opencv4` +LIBS = `pkg-config --libs opencv4` + +SRC = $(wildcard *.cpp) +OBJ = $(SRC:.cpp=.o) +TARGET = main + +all: $(TARGET) + +$(TARGET): $(OBJ) + $(CXX) $(OBJ) -o $@ $(LIBS) + +%.o: %.cpp + $(CXX) $(CXXFLAGS) -c $< -o $@ + +clean: + rm -f $(OBJ) $(TARGET) diff --git a/ora7/proj1/histo.cpp b/ora7/proj1/histo.cpp new file mode 100644 index 0000000..42352bc --- /dev/null +++ b/ora7/proj1/histo.cpp @@ -0,0 +1,126 @@ +/* +Kepfeld. gyak. - nehany segedfuggveny az orai anyag konnyebb szemleltetesehez. +*/ + +#include +#include +#include +#include +#include "histo.h" + +using namespace std; +using namespace cv; + +void Histo::calcHistoC1(const cv::Mat img, cv::Mat& histo) { + assert(img.type() == CV_8UC1); + + // CV_32U nem letezik, ha de CV_16U-t (ushort) hasznalhatsz, ha akarsz. + histo = Mat::zeros(256, 1, CV_32S); + for (int i = 0; i < img.rows; i++) + for (int j = 0; j < img.cols; j++) + histo.at(img.at(i, j))++; +} + + +void Histo::calcHistoC3(const cv::Mat img, vector& histo_vect) { + assert(img.type() == CV_8UC3); + + vector chs; + split(img.clone(), chs); + + Mat h0, h1, h2; + Histo::calcHistoC1(chs[0], h0); + Histo::calcHistoC1(chs[1], h1); + Histo::calcHistoC1(chs[2], h2); + + histo_vect.clear(); + histo_vect.push_back(h0); + histo_vect.push_back(h1); + histo_vect.push_back(h2); +} + + + +void Histo::drawHistoC1(const cv::Mat histo, cv::Mat& canvas, int channel) { + assert(histo.type() == CV_32S); + + int pad = 10; + canvas = Mat::zeros(200 + 2 * pad, 256 + 2 * pad, CV_8UC3); + + // a hisztogram alatti szurke sav rajzolasa + for (int i = 0; i < 10; ++i) { // 10 pixel vastag lesz, hogy jol latszodjon + for (int j = 0; j < 256; ++j) { + if (0 <= channel && channel <= 2) { + canvas.at(canvas.rows - 1 - i, j + pad)[channel] = j; + } + else { + canvas.at(canvas.rows - 1 - i, j + pad) = Vec3b(j, j, j); + } + } + } + + + Vec3b color(255, 255, 255); + if (0 <= channel && channel <= 2) { + color = Vec3b(0, 0, 0); + color[channel] = 255; + } + + + double minv, maxv; + minMaxLoc(histo, &minv, &maxv); + + double scale = 200 / maxv; // az ablak magassagahoz igazitom a hisztogram magassagat + + // a hisztogram rajzolasa + for (int i = 0; i < 256; ++i) { + // egy oszlop magassage (a line(Point(0, 0), Point(0, 1)) 2 pixelt rajzolna, ezert a -1) + int v = int(histo.at(i) * scale) - 1; + // canvas.rows-2-pad oldja meg, hogy a szurke sav felett kezdjuk a rajzolast + if (v >= 0) + line(canvas, Point(pad + i, canvas.rows - 2 - v - pad), Point(pad + i, canvas.rows - 2 - pad), color); + } +} + + +void Histo::drawHistoC3(const vector histos, vector& canvases) { + assert(histos.size() == 3 && + histos[0].type() == CV_32S && histos[1].type() == CV_32S && histos[2].type() == CV_32S); + + canvases.clear(); + for (int i = 0; i <= 2; ++i) { + Mat canvas; + Histo::drawHistoC1(histos[i], canvas, i); + canvases.push_back(canvas.clone()); + } +} + + +void Histo::showHisto(Mat img, string title, int wait) { + assert(img.type() == CV_8UC1 || img.type() == CV_8UC3); + + if (img.type() == CV_8UC1) { + Mat histo; + Histo::calcHistoC1(img, histo); + + // az ertekek konzolra iratasa + //cout << histo << endl; + + Mat canvas; + Histo::drawHistoC1(histo, canvas); + imshow(title, canvas); + } + else if (img.type() == CV_8UC3) { + vector histos; + Histo::calcHistoC3(img, histos); + + vector canvases; + Histo::drawHistoC3(histos, canvases); + + string str = "BGR"; + for (int i = 0; i <= 2; ++i) { + imshow(title + "-" + str[i], canvases[i]); + } + } + waitKey(wait); +} diff --git a/ora7/proj1/histo.h b/ora7/proj1/histo.h new file mode 100644 index 0000000..9178101 --- /dev/null +++ b/ora7/proj1/histo.h @@ -0,0 +1,32 @@ +/* +Kepfeld. gyak. - nehany segedfuggveny az orai anyag konnyebb szemleltetesehez. + 1 es 3 csatornas, csatornankent 8 bites kepekre: + Histo::showHisto(img); +*/ +#ifndef HISTO_H_ +#define HISTO_H_ + +#include +#include + +using namespace std; +using namespace cv; + +namespace Histo { + void calcHistoC1(const cv::Mat img, cv::Mat& histo); + void calcHistoC3(const cv::Mat img, vector& histo); + + void drawHistoC1(const cv::Mat histo, cv::Mat& canvas, int channel = -1); + void drawHistoC3(const vector histos, vector& canvases); + + /// + /// Egy kep hisztogramjanak megjelenitese. + /// + /// 1 vagy 3 csatornas input kep + /// ablaknev + /// varakoztatas + void showHisto(Mat img, string title = "histo", int wait = 0); +}; + + +#endif HISTO_H_ diff --git a/ora7/proj1/main.cpp b/ora7/proj1/main.cpp new file mode 100644 index 0000000..e35c3e2 --- /dev/null +++ b/ora7/proj1/main.cpp @@ -0,0 +1,30 @@ +#include "histo.h" +#include "opencv2/core/types.hpp" +#include +#include +#include +#include + +using namespace cv; + +int main(){ + Mat img = imread("../sajt.png", IMREAD_COLOR); + Mat gray, mask; + cvtColor(img, gray, COLOR_BGR2GRAY); + threshold(gray, mask, 250, 255, THRESH_BINARY_INV); + medianBlur(mask, mask, 3); + + std::vector> contours; + findContours(mask, contours, RETR_EXTERNAL, CHAIN_APPROX_NONE); + + for(int i = 0; i < contours.size(); i++){ + drawContours(img, contours, i, Scalar(0,0,255), 2); + imshow("img", img); + waitKey(); + } + + imshow("mask", mask); + + while(waitKey(3) != 'q'); + return 0; +} diff --git a/ora7/proj2/.clangd b/ora7/proj2/.clangd new file mode 100644 index 0000000..5f1474c --- /dev/null +++ b/ora7/proj2/.clangd @@ -0,0 +1,2 @@ +CompileFlags: + Add: [-I/usr/include/opencv4, -std=c++17] diff --git a/ora7/proj2/Makefile b/ora7/proj2/Makefile new file mode 100644 index 0000000..a350518 --- /dev/null +++ b/ora7/proj2/Makefile @@ -0,0 +1,18 @@ +CXX = g++ +CXXFLAGS = -Wall -O2 `pkg-config --cflags opencv4` +LIBS = `pkg-config --libs opencv4` + +SRC = $(wildcard *.cpp) +OBJ = $(SRC:.cpp=.o) +TARGET = main + +all: $(TARGET) + +$(TARGET): $(OBJ) + $(CXX) $(OBJ) -o $@ $(LIBS) + +%.o: %.cpp + $(CXX) $(CXXFLAGS) -c $< -o $@ + +clean: + rm -f $(OBJ) $(TARGET) diff --git a/ora7/proj2/histo.cpp b/ora7/proj2/histo.cpp new file mode 100644 index 0000000..42352bc --- /dev/null +++ b/ora7/proj2/histo.cpp @@ -0,0 +1,126 @@ +/* +Kepfeld. gyak. - nehany segedfuggveny az orai anyag konnyebb szemleltetesehez. +*/ + +#include +#include +#include +#include +#include "histo.h" + +using namespace std; +using namespace cv; + +void Histo::calcHistoC1(const cv::Mat img, cv::Mat& histo) { + assert(img.type() == CV_8UC1); + + // CV_32U nem letezik, ha de CV_16U-t (ushort) hasznalhatsz, ha akarsz. + histo = Mat::zeros(256, 1, CV_32S); + for (int i = 0; i < img.rows; i++) + for (int j = 0; j < img.cols; j++) + histo.at(img.at(i, j))++; +} + + +void Histo::calcHistoC3(const cv::Mat img, vector& histo_vect) { + assert(img.type() == CV_8UC3); + + vector chs; + split(img.clone(), chs); + + Mat h0, h1, h2; + Histo::calcHistoC1(chs[0], h0); + Histo::calcHistoC1(chs[1], h1); + Histo::calcHistoC1(chs[2], h2); + + histo_vect.clear(); + histo_vect.push_back(h0); + histo_vect.push_back(h1); + histo_vect.push_back(h2); +} + + + +void Histo::drawHistoC1(const cv::Mat histo, cv::Mat& canvas, int channel) { + assert(histo.type() == CV_32S); + + int pad = 10; + canvas = Mat::zeros(200 + 2 * pad, 256 + 2 * pad, CV_8UC3); + + // a hisztogram alatti szurke sav rajzolasa + for (int i = 0; i < 10; ++i) { // 10 pixel vastag lesz, hogy jol latszodjon + for (int j = 0; j < 256; ++j) { + if (0 <= channel && channel <= 2) { + canvas.at(canvas.rows - 1 - i, j + pad)[channel] = j; + } + else { + canvas.at(canvas.rows - 1 - i, j + pad) = Vec3b(j, j, j); + } + } + } + + + Vec3b color(255, 255, 255); + if (0 <= channel && channel <= 2) { + color = Vec3b(0, 0, 0); + color[channel] = 255; + } + + + double minv, maxv; + minMaxLoc(histo, &minv, &maxv); + + double scale = 200 / maxv; // az ablak magassagahoz igazitom a hisztogram magassagat + + // a hisztogram rajzolasa + for (int i = 0; i < 256; ++i) { + // egy oszlop magassage (a line(Point(0, 0), Point(0, 1)) 2 pixelt rajzolna, ezert a -1) + int v = int(histo.at(i) * scale) - 1; + // canvas.rows-2-pad oldja meg, hogy a szurke sav felett kezdjuk a rajzolast + if (v >= 0) + line(canvas, Point(pad + i, canvas.rows - 2 - v - pad), Point(pad + i, canvas.rows - 2 - pad), color); + } +} + + +void Histo::drawHistoC3(const vector histos, vector& canvases) { + assert(histos.size() == 3 && + histos[0].type() == CV_32S && histos[1].type() == CV_32S && histos[2].type() == CV_32S); + + canvases.clear(); + for (int i = 0; i <= 2; ++i) { + Mat canvas; + Histo::drawHistoC1(histos[i], canvas, i); + canvases.push_back(canvas.clone()); + } +} + + +void Histo::showHisto(Mat img, string title, int wait) { + assert(img.type() == CV_8UC1 || img.type() == CV_8UC3); + + if (img.type() == CV_8UC1) { + Mat histo; + Histo::calcHistoC1(img, histo); + + // az ertekek konzolra iratasa + //cout << histo << endl; + + Mat canvas; + Histo::drawHistoC1(histo, canvas); + imshow(title, canvas); + } + else if (img.type() == CV_8UC3) { + vector histos; + Histo::calcHistoC3(img, histos); + + vector canvases; + Histo::drawHistoC3(histos, canvases); + + string str = "BGR"; + for (int i = 0; i <= 2; ++i) { + imshow(title + "-" + str[i], canvases[i]); + } + } + waitKey(wait); +} diff --git a/ora7/proj2/histo.h b/ora7/proj2/histo.h new file mode 100644 index 0000000..9178101 --- /dev/null +++ b/ora7/proj2/histo.h @@ -0,0 +1,32 @@ +/* +Kepfeld. gyak. - nehany segedfuggveny az orai anyag konnyebb szemleltetesehez. + 1 es 3 csatornas, csatornankent 8 bites kepekre: + Histo::showHisto(img); +*/ +#ifndef HISTO_H_ +#define HISTO_H_ + +#include +#include + +using namespace std; +using namespace cv; + +namespace Histo { + void calcHistoC1(const cv::Mat img, cv::Mat& histo); + void calcHistoC3(const cv::Mat img, vector& histo); + + void drawHistoC1(const cv::Mat histo, cv::Mat& canvas, int channel = -1); + void drawHistoC3(const vector histos, vector& canvases); + + /// + /// Egy kep hisztogramjanak megjelenitese. + /// + /// 1 vagy 3 csatornas input kep + /// ablaknev + /// varakoztatas + void showHisto(Mat img, string title = "histo", int wait = 0); +}; + + +#endif HISTO_H_ diff --git a/ora7/proj2/main.cpp b/ora7/proj2/main.cpp new file mode 100644 index 0000000..1c0d8ed --- /dev/null +++ b/ora7/proj2/main.cpp @@ -0,0 +1,30 @@ +#include "histo.h" +#include "opencv2/core/types.hpp" +#include +#include +#include +#include + +using namespace cv; + +int main(){ + Mat img = imread("../dog.jpg", IMREAD_COLOR); + Mat gray, mask; + cvtColor(img, gray, COLOR_BGR2GRAY); + threshold(gray, mask, 120, 255, THRESH_BINARY); + + std::vector> contours; + findContours(mask, contours, RETR_EXTERNAL, CHAIN_APPROX_NONE); + + for(int i = 0; i < contours.size(); i++){ + if(contours[i].size() > 500){ + drawContours(img, contours, i, Scalar(0,0,255), 2); + } + waitKey(); + } + + imshow("img", img); + + while(waitKey(3) != 'q'); + return 0; +} diff --git a/ora7/proj3/.clangd b/ora7/proj3/.clangd new file mode 100644 index 0000000..5f1474c --- /dev/null +++ b/ora7/proj3/.clangd @@ -0,0 +1,2 @@ +CompileFlags: + Add: [-I/usr/include/opencv4, -std=c++17] diff --git a/ora7/proj3/Makefile b/ora7/proj3/Makefile new file mode 100644 index 0000000..a350518 --- /dev/null +++ b/ora7/proj3/Makefile @@ -0,0 +1,18 @@ +CXX = g++ +CXXFLAGS = -Wall -O2 `pkg-config --cflags opencv4` +LIBS = `pkg-config --libs opencv4` + +SRC = $(wildcard *.cpp) +OBJ = $(SRC:.cpp=.o) +TARGET = main + +all: $(TARGET) + +$(TARGET): $(OBJ) + $(CXX) $(OBJ) -o $@ $(LIBS) + +%.o: %.cpp + $(CXX) $(CXXFLAGS) -c $< -o $@ + +clean: + rm -f $(OBJ) $(TARGET) diff --git a/ora7/proj3/histo.cpp b/ora7/proj3/histo.cpp new file mode 100644 index 0000000..42352bc --- /dev/null +++ b/ora7/proj3/histo.cpp @@ -0,0 +1,126 @@ +/* +Kepfeld. gyak. - nehany segedfuggveny az orai anyag konnyebb szemleltetesehez. +*/ + +#include +#include +#include +#include +#include "histo.h" + +using namespace std; +using namespace cv; + +void Histo::calcHistoC1(const cv::Mat img, cv::Mat& histo) { + assert(img.type() == CV_8UC1); + + // CV_32U nem letezik, ha de CV_16U-t (ushort) hasznalhatsz, ha akarsz. + histo = Mat::zeros(256, 1, CV_32S); + for (int i = 0; i < img.rows; i++) + for (int j = 0; j < img.cols; j++) + histo.at(img.at(i, j))++; +} + + +void Histo::calcHistoC3(const cv::Mat img, vector& histo_vect) { + assert(img.type() == CV_8UC3); + + vector chs; + split(img.clone(), chs); + + Mat h0, h1, h2; + Histo::calcHistoC1(chs[0], h0); + Histo::calcHistoC1(chs[1], h1); + Histo::calcHistoC1(chs[2], h2); + + histo_vect.clear(); + histo_vect.push_back(h0); + histo_vect.push_back(h1); + histo_vect.push_back(h2); +} + + + +void Histo::drawHistoC1(const cv::Mat histo, cv::Mat& canvas, int channel) { + assert(histo.type() == CV_32S); + + int pad = 10; + canvas = Mat::zeros(200 + 2 * pad, 256 + 2 * pad, CV_8UC3); + + // a hisztogram alatti szurke sav rajzolasa + for (int i = 0; i < 10; ++i) { // 10 pixel vastag lesz, hogy jol latszodjon + for (int j = 0; j < 256; ++j) { + if (0 <= channel && channel <= 2) { + canvas.at(canvas.rows - 1 - i, j + pad)[channel] = j; + } + else { + canvas.at(canvas.rows - 1 - i, j + pad) = Vec3b(j, j, j); + } + } + } + + + Vec3b color(255, 255, 255); + if (0 <= channel && channel <= 2) { + color = Vec3b(0, 0, 0); + color[channel] = 255; + } + + + double minv, maxv; + minMaxLoc(histo, &minv, &maxv); + + double scale = 200 / maxv; // az ablak magassagahoz igazitom a hisztogram magassagat + + // a hisztogram rajzolasa + for (int i = 0; i < 256; ++i) { + // egy oszlop magassage (a line(Point(0, 0), Point(0, 1)) 2 pixelt rajzolna, ezert a -1) + int v = int(histo.at(i) * scale) - 1; + // canvas.rows-2-pad oldja meg, hogy a szurke sav felett kezdjuk a rajzolast + if (v >= 0) + line(canvas, Point(pad + i, canvas.rows - 2 - v - pad), Point(pad + i, canvas.rows - 2 - pad), color); + } +} + + +void Histo::drawHistoC3(const vector histos, vector& canvases) { + assert(histos.size() == 3 && + histos[0].type() == CV_32S && histos[1].type() == CV_32S && histos[2].type() == CV_32S); + + canvases.clear(); + for (int i = 0; i <= 2; ++i) { + Mat canvas; + Histo::drawHistoC1(histos[i], canvas, i); + canvases.push_back(canvas.clone()); + } +} + + +void Histo::showHisto(Mat img, string title, int wait) { + assert(img.type() == CV_8UC1 || img.type() == CV_8UC3); + + if (img.type() == CV_8UC1) { + Mat histo; + Histo::calcHistoC1(img, histo); + + // az ertekek konzolra iratasa + //cout << histo << endl; + + Mat canvas; + Histo::drawHistoC1(histo, canvas); + imshow(title, canvas); + } + else if (img.type() == CV_8UC3) { + vector histos; + Histo::calcHistoC3(img, histos); + + vector canvases; + Histo::drawHistoC3(histos, canvases); + + string str = "BGR"; + for (int i = 0; i <= 2; ++i) { + imshow(title + "-" + str[i], canvases[i]); + } + } + waitKey(wait); +} diff --git a/ora7/proj3/histo.h b/ora7/proj3/histo.h new file mode 100644 index 0000000..9178101 --- /dev/null +++ b/ora7/proj3/histo.h @@ -0,0 +1,32 @@ +/* +Kepfeld. gyak. - nehany segedfuggveny az orai anyag konnyebb szemleltetesehez. + 1 es 3 csatornas, csatornankent 8 bites kepekre: + Histo::showHisto(img); +*/ +#ifndef HISTO_H_ +#define HISTO_H_ + +#include +#include + +using namespace std; +using namespace cv; + +namespace Histo { + void calcHistoC1(const cv::Mat img, cv::Mat& histo); + void calcHistoC3(const cv::Mat img, vector& histo); + + void drawHistoC1(const cv::Mat histo, cv::Mat& canvas, int channel = -1); + void drawHistoC3(const vector histos, vector& canvases); + + /// + /// Egy kep hisztogramjanak megjelenitese. + /// + /// 1 vagy 3 csatornas input kep + /// ablaknev + /// varakoztatas + void showHisto(Mat img, string title = "histo", int wait = 0); +}; + + +#endif HISTO_H_ diff --git a/ora7/proj3/main.cpp b/ora7/proj3/main.cpp new file mode 100644 index 0000000..0c72b59 --- /dev/null +++ b/ora7/proj3/main.cpp @@ -0,0 +1,34 @@ +#include "histo.h" +#include "opencv2/core/types.hpp" +#include +#include +#include +#include +#include + +using namespace cv; + +int main(){ + Mat img = imread("../kincseslada.png", IMREAD_COLOR); + Mat gray, mask; + cvtColor(img, gray, COLOR_BGR2GRAY); + threshold(gray, mask, 230, 255, THRESH_BINARY_INV); + medianBlur(mask, mask, 5); + + + std::vector> contours; + findContours(mask, contours, RETR_EXTERNAL, CHAIN_APPROX_NONE); + + assert(contours.size() == 2); + + if(contours[0].size() > contours[1].size()){ + drawContours(img, contours, 0, Scalar(0,0,255), 2); + }else{ + drawContours(img, contours, 1, Scalar(0,0,255), 2); + } + + imshow("img", img); + + while(waitKey(3) != 'q'); + return 0; +} diff --git a/ora7/proj4/.clangd b/ora7/proj4/.clangd new file mode 100644 index 0000000..5f1474c --- /dev/null +++ b/ora7/proj4/.clangd @@ -0,0 +1,2 @@ +CompileFlags: + Add: [-I/usr/include/opencv4, -std=c++17] diff --git a/ora7/proj4/Makefile b/ora7/proj4/Makefile new file mode 100644 index 0000000..a350518 --- /dev/null +++ b/ora7/proj4/Makefile @@ -0,0 +1,18 @@ +CXX = g++ +CXXFLAGS = -Wall -O2 `pkg-config --cflags opencv4` +LIBS = `pkg-config --libs opencv4` + +SRC = $(wildcard *.cpp) +OBJ = $(SRC:.cpp=.o) +TARGET = main + +all: $(TARGET) + +$(TARGET): $(OBJ) + $(CXX) $(OBJ) -o $@ $(LIBS) + +%.o: %.cpp + $(CXX) $(CXXFLAGS) -c $< -o $@ + +clean: + rm -f $(OBJ) $(TARGET) diff --git a/ora7/proj4/histo.cpp b/ora7/proj4/histo.cpp new file mode 100644 index 0000000..42352bc --- /dev/null +++ b/ora7/proj4/histo.cpp @@ -0,0 +1,126 @@ +/* +Kepfeld. gyak. - nehany segedfuggveny az orai anyag konnyebb szemleltetesehez. +*/ + +#include +#include +#include +#include +#include "histo.h" + +using namespace std; +using namespace cv; + +void Histo::calcHistoC1(const cv::Mat img, cv::Mat& histo) { + assert(img.type() == CV_8UC1); + + // CV_32U nem letezik, ha de CV_16U-t (ushort) hasznalhatsz, ha akarsz. + histo = Mat::zeros(256, 1, CV_32S); + for (int i = 0; i < img.rows; i++) + for (int j = 0; j < img.cols; j++) + histo.at(img.at(i, j))++; +} + + +void Histo::calcHistoC3(const cv::Mat img, vector& histo_vect) { + assert(img.type() == CV_8UC3); + + vector chs; + split(img.clone(), chs); + + Mat h0, h1, h2; + Histo::calcHistoC1(chs[0], h0); + Histo::calcHistoC1(chs[1], h1); + Histo::calcHistoC1(chs[2], h2); + + histo_vect.clear(); + histo_vect.push_back(h0); + histo_vect.push_back(h1); + histo_vect.push_back(h2); +} + + + +void Histo::drawHistoC1(const cv::Mat histo, cv::Mat& canvas, int channel) { + assert(histo.type() == CV_32S); + + int pad = 10; + canvas = Mat::zeros(200 + 2 * pad, 256 + 2 * pad, CV_8UC3); + + // a hisztogram alatti szurke sav rajzolasa + for (int i = 0; i < 10; ++i) { // 10 pixel vastag lesz, hogy jol latszodjon + for (int j = 0; j < 256; ++j) { + if (0 <= channel && channel <= 2) { + canvas.at(canvas.rows - 1 - i, j + pad)[channel] = j; + } + else { + canvas.at(canvas.rows - 1 - i, j + pad) = Vec3b(j, j, j); + } + } + } + + + Vec3b color(255, 255, 255); + if (0 <= channel && channel <= 2) { + color = Vec3b(0, 0, 0); + color[channel] = 255; + } + + + double minv, maxv; + minMaxLoc(histo, &minv, &maxv); + + double scale = 200 / maxv; // az ablak magassagahoz igazitom a hisztogram magassagat + + // a hisztogram rajzolasa + for (int i = 0; i < 256; ++i) { + // egy oszlop magassage (a line(Point(0, 0), Point(0, 1)) 2 pixelt rajzolna, ezert a -1) + int v = int(histo.at(i) * scale) - 1; + // canvas.rows-2-pad oldja meg, hogy a szurke sav felett kezdjuk a rajzolast + if (v >= 0) + line(canvas, Point(pad + i, canvas.rows - 2 - v - pad), Point(pad + i, canvas.rows - 2 - pad), color); + } +} + + +void Histo::drawHistoC3(const vector histos, vector& canvases) { + assert(histos.size() == 3 && + histos[0].type() == CV_32S && histos[1].type() == CV_32S && histos[2].type() == CV_32S); + + canvases.clear(); + for (int i = 0; i <= 2; ++i) { + Mat canvas; + Histo::drawHistoC1(histos[i], canvas, i); + canvases.push_back(canvas.clone()); + } +} + + +void Histo::showHisto(Mat img, string title, int wait) { + assert(img.type() == CV_8UC1 || img.type() == CV_8UC3); + + if (img.type() == CV_8UC1) { + Mat histo; + Histo::calcHistoC1(img, histo); + + // az ertekek konzolra iratasa + //cout << histo << endl; + + Mat canvas; + Histo::drawHistoC1(histo, canvas); + imshow(title, canvas); + } + else if (img.type() == CV_8UC3) { + vector histos; + Histo::calcHistoC3(img, histos); + + vector canvases; + Histo::drawHistoC3(histos, canvases); + + string str = "BGR"; + for (int i = 0; i <= 2; ++i) { + imshow(title + "-" + str[i], canvases[i]); + } + } + waitKey(wait); +} diff --git a/ora7/proj4/histo.h b/ora7/proj4/histo.h new file mode 100644 index 0000000..9178101 --- /dev/null +++ b/ora7/proj4/histo.h @@ -0,0 +1,32 @@ +/* +Kepfeld. gyak. - nehany segedfuggveny az orai anyag konnyebb szemleltetesehez. + 1 es 3 csatornas, csatornankent 8 bites kepekre: + Histo::showHisto(img); +*/ +#ifndef HISTO_H_ +#define HISTO_H_ + +#include +#include + +using namespace std; +using namespace cv; + +namespace Histo { + void calcHistoC1(const cv::Mat img, cv::Mat& histo); + void calcHistoC3(const cv::Mat img, vector& histo); + + void drawHistoC1(const cv::Mat histo, cv::Mat& canvas, int channel = -1); + void drawHistoC3(const vector histos, vector& canvases); + + /// + /// Egy kep hisztogramjanak megjelenitese. + /// + /// 1 vagy 3 csatornas input kep + /// ablaknev + /// varakoztatas + void showHisto(Mat img, string title = "histo", int wait = 0); +}; + + +#endif HISTO_H_ diff --git a/ora7/proj4/main.cpp b/ora7/proj4/main.cpp new file mode 100644 index 0000000..1145cea --- /dev/null +++ b/ora7/proj4/main.cpp @@ -0,0 +1,42 @@ +#include "histo.h" +#include "opencv2/core/types.hpp" +#include +#include +#include +#include +#include +#include +#include + +using namespace cv; + +int main(){ + Mat img = imread("../some_objects.png", IMREAD_COLOR); + Mat gray, mask; + cvtColor(img, gray, COLOR_BGR2GRAY); + threshold(gray, mask, 230, 255, THRESH_BINARY); + + std::vector> contours; + findContours(mask, contours, RETR_EXTERNAL, CHAIN_APPROX_NONE); + + for(int i = 0; i < contours.size(); i++){ + Mat canvas = img.clone(); + for(int j = 0; j < i; j++){ + double d = matchShapes(contours[i], contours[j], CONTOURS_MATCH_I2, 0); + + std::string s = to_string(d); + + drawContours(canvas, contours, i, Scalar(0,0,255), 2); + drawContours(canvas, contours, j, Scalar(0,0,255), 2); + + line(canvas, contours[i][0], contours[j][0], Scalar(100,100,100), 2); + + putText(canvas, s, contours[j][0], FONT_HERSHEY_PLAIN, 1.5, Scalar(255, 255, 255)); + } + } + + imshow("img", img); + + while(waitKey(3) != 'q'); + return 0; +} diff --git a/ora7/proj5/.clangd b/ora7/proj5/.clangd new file mode 100644 index 0000000..5f1474c --- /dev/null +++ b/ora7/proj5/.clangd @@ -0,0 +1,2 @@ +CompileFlags: + Add: [-I/usr/include/opencv4, -std=c++17] diff --git a/ora7/proj5/Makefile b/ora7/proj5/Makefile new file mode 100644 index 0000000..a350518 --- /dev/null +++ b/ora7/proj5/Makefile @@ -0,0 +1,18 @@ +CXX = g++ +CXXFLAGS = -Wall -O2 `pkg-config --cflags opencv4` +LIBS = `pkg-config --libs opencv4` + +SRC = $(wildcard *.cpp) +OBJ = $(SRC:.cpp=.o) +TARGET = main + +all: $(TARGET) + +$(TARGET): $(OBJ) + $(CXX) $(OBJ) -o $@ $(LIBS) + +%.o: %.cpp + $(CXX) $(CXXFLAGS) -c $< -o $@ + +clean: + rm -f $(OBJ) $(TARGET) diff --git a/ora7/proj5/histo.cpp b/ora7/proj5/histo.cpp new file mode 100644 index 0000000..42352bc --- /dev/null +++ b/ora7/proj5/histo.cpp @@ -0,0 +1,126 @@ +/* +Kepfeld. gyak. - nehany segedfuggveny az orai anyag konnyebb szemleltetesehez. +*/ + +#include +#include +#include +#include +#include "histo.h" + +using namespace std; +using namespace cv; + +void Histo::calcHistoC1(const cv::Mat img, cv::Mat& histo) { + assert(img.type() == CV_8UC1); + + // CV_32U nem letezik, ha de CV_16U-t (ushort) hasznalhatsz, ha akarsz. + histo = Mat::zeros(256, 1, CV_32S); + for (int i = 0; i < img.rows; i++) + for (int j = 0; j < img.cols; j++) + histo.at(img.at(i, j))++; +} + + +void Histo::calcHistoC3(const cv::Mat img, vector& histo_vect) { + assert(img.type() == CV_8UC3); + + vector chs; + split(img.clone(), chs); + + Mat h0, h1, h2; + Histo::calcHistoC1(chs[0], h0); + Histo::calcHistoC1(chs[1], h1); + Histo::calcHistoC1(chs[2], h2); + + histo_vect.clear(); + histo_vect.push_back(h0); + histo_vect.push_back(h1); + histo_vect.push_back(h2); +} + + + +void Histo::drawHistoC1(const cv::Mat histo, cv::Mat& canvas, int channel) { + assert(histo.type() == CV_32S); + + int pad = 10; + canvas = Mat::zeros(200 + 2 * pad, 256 + 2 * pad, CV_8UC3); + + // a hisztogram alatti szurke sav rajzolasa + for (int i = 0; i < 10; ++i) { // 10 pixel vastag lesz, hogy jol latszodjon + for (int j = 0; j < 256; ++j) { + if (0 <= channel && channel <= 2) { + canvas.at(canvas.rows - 1 - i, j + pad)[channel] = j; + } + else { + canvas.at(canvas.rows - 1 - i, j + pad) = Vec3b(j, j, j); + } + } + } + + + Vec3b color(255, 255, 255); + if (0 <= channel && channel <= 2) { + color = Vec3b(0, 0, 0); + color[channel] = 255; + } + + + double minv, maxv; + minMaxLoc(histo, &minv, &maxv); + + double scale = 200 / maxv; // az ablak magassagahoz igazitom a hisztogram magassagat + + // a hisztogram rajzolasa + for (int i = 0; i < 256; ++i) { + // egy oszlop magassage (a line(Point(0, 0), Point(0, 1)) 2 pixelt rajzolna, ezert a -1) + int v = int(histo.at(i) * scale) - 1; + // canvas.rows-2-pad oldja meg, hogy a szurke sav felett kezdjuk a rajzolast + if (v >= 0) + line(canvas, Point(pad + i, canvas.rows - 2 - v - pad), Point(pad + i, canvas.rows - 2 - pad), color); + } +} + + +void Histo::drawHistoC3(const vector histos, vector& canvases) { + assert(histos.size() == 3 && + histos[0].type() == CV_32S && histos[1].type() == CV_32S && histos[2].type() == CV_32S); + + canvases.clear(); + for (int i = 0; i <= 2; ++i) { + Mat canvas; + Histo::drawHistoC1(histos[i], canvas, i); + canvases.push_back(canvas.clone()); + } +} + + +void Histo::showHisto(Mat img, string title, int wait) { + assert(img.type() == CV_8UC1 || img.type() == CV_8UC3); + + if (img.type() == CV_8UC1) { + Mat histo; + Histo::calcHistoC1(img, histo); + + // az ertekek konzolra iratasa + //cout << histo << endl; + + Mat canvas; + Histo::drawHistoC1(histo, canvas); + imshow(title, canvas); + } + else if (img.type() == CV_8UC3) { + vector histos; + Histo::calcHistoC3(img, histos); + + vector canvases; + Histo::drawHistoC3(histos, canvases); + + string str = "BGR"; + for (int i = 0; i <= 2; ++i) { + imshow(title + "-" + str[i], canvases[i]); + } + } + waitKey(wait); +} diff --git a/ora7/proj5/histo.h b/ora7/proj5/histo.h new file mode 100644 index 0000000..9178101 --- /dev/null +++ b/ora7/proj5/histo.h @@ -0,0 +1,32 @@ +/* +Kepfeld. gyak. - nehany segedfuggveny az orai anyag konnyebb szemleltetesehez. + 1 es 3 csatornas, csatornankent 8 bites kepekre: + Histo::showHisto(img); +*/ +#ifndef HISTO_H_ +#define HISTO_H_ + +#include +#include + +using namespace std; +using namespace cv; + +namespace Histo { + void calcHistoC1(const cv::Mat img, cv::Mat& histo); + void calcHistoC3(const cv::Mat img, vector& histo); + + void drawHistoC1(const cv::Mat histo, cv::Mat& canvas, int channel = -1); + void drawHistoC3(const vector histos, vector& canvases); + + /// + /// Egy kep hisztogramjanak megjelenitese. + /// + /// 1 vagy 3 csatornas input kep + /// ablaknev + /// varakoztatas + void showHisto(Mat img, string title = "histo", int wait = 0); +}; + + +#endif HISTO_H_ diff --git a/ora7/proj5/main.cpp b/ora7/proj5/main.cpp new file mode 100644 index 0000000..1145cea --- /dev/null +++ b/ora7/proj5/main.cpp @@ -0,0 +1,42 @@ +#include "histo.h" +#include "opencv2/core/types.hpp" +#include +#include +#include +#include +#include +#include +#include + +using namespace cv; + +int main(){ + Mat img = imread("../some_objects.png", IMREAD_COLOR); + Mat gray, mask; + cvtColor(img, gray, COLOR_BGR2GRAY); + threshold(gray, mask, 230, 255, THRESH_BINARY); + + std::vector> contours; + findContours(mask, contours, RETR_EXTERNAL, CHAIN_APPROX_NONE); + + for(int i = 0; i < contours.size(); i++){ + Mat canvas = img.clone(); + for(int j = 0; j < i; j++){ + double d = matchShapes(contours[i], contours[j], CONTOURS_MATCH_I2, 0); + + std::string s = to_string(d); + + drawContours(canvas, contours, i, Scalar(0,0,255), 2); + drawContours(canvas, contours, j, Scalar(0,0,255), 2); + + line(canvas, contours[i][0], contours[j][0], Scalar(100,100,100), 2); + + putText(canvas, s, contours[j][0], FONT_HERSHEY_PLAIN, 1.5, Scalar(255, 255, 255)); + } + } + + imshow("img", img); + + while(waitKey(3) != 'q'); + return 0; +} diff --git a/ora7/rubber_pads.png b/ora7/rubber_pads.png new file mode 100644 index 0000000..112fa3b Binary files /dev/null and b/ora7/rubber_pads.png differ diff --git a/ora7/sajt.png b/ora7/sajt.png new file mode 100644 index 0000000..d6bc1fa Binary files /dev/null and b/ora7/sajt.png differ diff --git a/ora7/some_objects.png b/ora7/some_objects.png new file mode 100644 index 0000000..7d85afd Binary files /dev/null and b/ora7/some_objects.png differ diff --git a/ora7/soybean_leafminer.jpg b/ora7/soybean_leafminer.jpg new file mode 100644 index 0000000..7ba8aa4 Binary files /dev/null and b/ora7/soybean_leafminer.jpg differ diff --git a/ora7/szita.jpg b/ora7/szita.jpg new file mode 100644 index 0000000..12207b6 Binary files /dev/null and b/ora7/szita.jpg differ