final
BIN
ora5/proj1/filtered_stud.png
Normal file
|
After Width: | Height: | Size: 46 KiB |
BIN
ora5/proj1/gray_stud.png
Normal file
|
After Width: | Height: | Size: 32 KiB |
BIN
ora5/proj1/histo.o
Normal file
45
ora5/proj1/m2
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
#include "histo.h"
|
||||||
|
#include <opencv2/core.hpp>
|
||||||
|
#include <opencv2/highgui.hpp>
|
||||||
|
#include <opencv2/imgproc.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using namespace cv;
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
Mat img = imread("../madar.jpg", IMREAD_COLOR);
|
||||||
|
imshow("img", img);
|
||||||
|
|
||||||
|
Histo::showHisto(img, "histo", 1);
|
||||||
|
|
||||||
|
std::vector<Mat> 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;
|
||||||
|
}
|
||||||
BIN
ora5/proj1/main
Executable file
@@ -1,45 +1,75 @@
|
|||||||
#include "histo.h"
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
#include <opencv2/core.hpp>
|
#include <opencv2/core.hpp>
|
||||||
#include <opencv2/highgui.hpp>
|
#include <opencv2/highgui.hpp>
|
||||||
#include <opencv2/imgproc.hpp>
|
#include <opencv2/imgproc.hpp>
|
||||||
#include <iostream>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
using namespace cv;
|
using namespace cv;
|
||||||
|
|
||||||
|
void kordetektalo1(const Mat& gray, vector<Vec3f>& circles) {
|
||||||
|
|
||||||
|
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(){
|
int main(){
|
||||||
Mat img = imread("../madar.jpg", IMREAD_COLOR);
|
Mat img = imread("past.jpg", IMREAD_COLOR);
|
||||||
imshow("img", img);
|
if(img.empty()){
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
Histo::showHisto(img, "histo", 1);
|
// 1. Konvertáld szürkeskálássá az img képet
|
||||||
|
Mat gray;
|
||||||
std::vector<Mat> chs;
|
cvtColor(img, gray, COLOR_BGR2GRAY);
|
||||||
split(img, chs);
|
imwrite("gray_stud.png", gray);
|
||||||
|
|
||||||
/*imshow("r", chs[2]);
|
|
||||||
imshow("g", chs[1]);
|
|
||||||
imshow("b", chs[0]);*/
|
|
||||||
|
|
||||||
|
|
||||||
Mat dest1, dest2, dest3, dest4, mask;
|
vector<Vec3f> circles;
|
||||||
|
kordetektalo1(gray, circles);
|
||||||
|
|
||||||
//dest1 = img > 100;
|
// 2. Végezz mediánszűrés 11x11-es ablakmérettel.
|
||||||
//threshold(img, dest2, 100, 255, THRESH_BINARY);
|
Mat mb2;
|
||||||
//threshold(img, dest3, 100, 255, THRESH_OTSU);
|
medianBlur(img, mb2, 11);
|
||||||
//threshold(img, dest4, 100, 255, THRESH_TRIANGLE);
|
imwrite("filtered_stud.png", mb2);
|
||||||
|
|
||||||
//medianBlur(dest1, dest1, 3);
|
// 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;
|
||||||
|
|
||||||
threshold(chs[0], mask, 120, 255, THRESH_BINARY|cv::THRESH_OTSU);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
img.copyTo(dest2, mask);
|
imwrite("result_stud.png", img);
|
||||||
|
|
||||||
|
|
||||||
//imshow("dest1", dest1);
|
// 4. Határozd meg a körök középpontja alá eső pixelek
|
||||||
imshow("dest2", dest2);
|
// KÉK komponensének átlagát a SZŰRT képen.
|
||||||
//imshow("dest3", dest3);
|
double mean_v = 0;
|
||||||
//imshow("dest4", dest4);
|
vector<Mat> chs;
|
||||||
|
split(circles, chs); //bgr
|
||||||
|
int count = 0;
|
||||||
|
for(auto c : circles){
|
||||||
|
int x = c[0];
|
||||||
|
int y = c[1];
|
||||||
|
mean_v += img.at<uchar>(y,x);
|
||||||
|
}
|
||||||
|
mean_v /= circles.size();
|
||||||
|
|
||||||
|
|
||||||
|
// Jelenitsd meg az atlagot a standard kimeneten.
|
||||||
|
// cout << mean_v << endl;
|
||||||
|
|
||||||
|
waitKey();
|
||||||
|
|
||||||
while(waitKey(3) != 'q');
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
ora5/proj1/main.o
Normal file
BIN
ora5/proj1/past.jpg
Normal file
|
After Width: | Height: | Size: 27 KiB |
BIN
ora5/proj1/result_stud.png
Normal file
|
After Width: | Height: | Size: 88 KiB |
2
ora7/.clangd
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
CompileFlags:
|
||||||
|
Add: [-I/usr/include/opencv4, -std=c++17]
|
||||||
BIN
ora7/Képek (kontúrkezelés)-20251120.zip
Normal file
18
ora7/Makefile
Normal file
@@ -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)
|
||||||
BIN
ora7/dog.jpg
Normal file
|
After Width: | Height: | Size: 7.9 KiB |
BIN
ora7/form.png
Normal file
|
After Width: | Height: | Size: 262 KiB |
BIN
ora7/gumialatet3.jpg
Normal file
|
After Width: | Height: | Size: 78 KiB |
BIN
ora7/kincseslada.png
Normal file
|
After Width: | Height: | Size: 337 KiB |
BIN
ora7/ko.png
Normal file
|
After Width: | Height: | Size: 65 KiB |
BIN
ora7/leaves.jpg
Normal file
|
After Width: | Height: | Size: 31 KiB |
26
ora7/main.cpp
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#include "histo.h"
|
||||||
|
#include <opencv2/core.hpp>
|
||||||
|
#include <opencv2/highgui.hpp>
|
||||||
|
#include <opencv2/imgproc.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
BIN
ora7/objects_prop.png
Normal file
|
After Width: | Height: | Size: 26 KiB |
BIN
ora7/objects_prop1.png
Normal file
|
After Width: | Height: | Size: 15 KiB |
BIN
ora7/objektumok.png
Normal file
|
After Width: | Height: | Size: 6.0 KiB |
BIN
ora7/ollo.png
Normal file
|
After Width: | Height: | Size: 80 KiB |
BIN
ora7/perecek.zip
Normal file
BIN
ora7/perecek/1.png
Normal file
|
After Width: | Height: | Size: 579 KiB |
BIN
ora7/perecek/2.png
Normal file
|
After Width: | Height: | Size: 532 KiB |
BIN
ora7/perecek/3.png
Normal file
|
After Width: | Height: | Size: 542 KiB |
BIN
ora7/perecek/4.png
Normal file
|
After Width: | Height: | Size: 515 KiB |
BIN
ora7/pretzel.png
Normal file
|
After Width: | Height: | Size: 28 KiB |
2
ora7/proj1/.clangd
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
CompileFlags:
|
||||||
|
Add: [-I/usr/include/opencv4, -std=c++17]
|
||||||
18
ora7/proj1/Makefile
Normal file
@@ -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)
|
||||||
126
ora7/proj1/histo.cpp
Normal file
@@ -0,0 +1,126 @@
|
|||||||
|
/*
|
||||||
|
Kepfeld. gyak. - nehany segedfuggveny az orai anyag konnyebb szemleltetesehez.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <opencv2/core.hpp>
|
||||||
|
#include <opencv2/imgproc.hpp>
|
||||||
|
#include <opencv2/highgui.hpp>
|
||||||
|
#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<int>(img.at<uchar>(i, j))++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Histo::calcHistoC3(const cv::Mat img, vector<cv::Mat>& histo_vect) {
|
||||||
|
assert(img.type() == CV_8UC3);
|
||||||
|
|
||||||
|
vector<Mat> 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<Vec3b>(canvas.rows - 1 - i, j + pad)[channel] = j;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
canvas.at<Vec3b>(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<int>(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<cv::Mat> histos, vector<cv::Mat>& 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<Mat> histos;
|
||||||
|
Histo::calcHistoC3(img, histos);
|
||||||
|
|
||||||
|
vector<Mat> canvases;
|
||||||
|
Histo::drawHistoC3(histos, canvases);
|
||||||
|
|
||||||
|
string str = "BGR";
|
||||||
|
for (int i = 0; i <= 2; ++i) {
|
||||||
|
imshow(title + "-" + str[i], canvases[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
waitKey(wait);
|
||||||
|
}
|
||||||
32
ora7/proj1/histo.h
Normal file
@@ -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 <vector>
|
||||||
|
#include <opencv2/core.hpp>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace cv;
|
||||||
|
|
||||||
|
namespace Histo {
|
||||||
|
void calcHistoC1(const cv::Mat img, cv::Mat& histo);
|
||||||
|
void calcHistoC3(const cv::Mat img, vector<cv::Mat>& histo);
|
||||||
|
|
||||||
|
void drawHistoC1(const cv::Mat histo, cv::Mat& canvas, int channel = -1);
|
||||||
|
void drawHistoC3(const vector<cv::Mat> histos, vector<cv::Mat>& canvases);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Egy kep hisztogramjanak megjelenitese.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="img">1 vagy 3 csatornas input kep</param>
|
||||||
|
/// <param name="title">ablaknev</param>
|
||||||
|
/// <param name="wait">varakoztatas</param>
|
||||||
|
void showHisto(Mat img, string title = "histo", int wait = 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif HISTO_H_
|
||||||
30
ora7/proj1/main.cpp
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
#include "histo.h"
|
||||||
|
#include "opencv2/core/types.hpp"
|
||||||
|
#include <opencv2/core.hpp>
|
||||||
|
#include <opencv2/highgui.hpp>
|
||||||
|
#include <opencv2/imgproc.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
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<std::vector<Point>> 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;
|
||||||
|
}
|
||||||
2
ora7/proj2/.clangd
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
CompileFlags:
|
||||||
|
Add: [-I/usr/include/opencv4, -std=c++17]
|
||||||
18
ora7/proj2/Makefile
Normal file
@@ -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)
|
||||||
126
ora7/proj2/histo.cpp
Normal file
@@ -0,0 +1,126 @@
|
|||||||
|
/*
|
||||||
|
Kepfeld. gyak. - nehany segedfuggveny az orai anyag konnyebb szemleltetesehez.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <opencv2/core.hpp>
|
||||||
|
#include <opencv2/imgproc.hpp>
|
||||||
|
#include <opencv2/highgui.hpp>
|
||||||
|
#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<int>(img.at<uchar>(i, j))++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Histo::calcHistoC3(const cv::Mat img, vector<cv::Mat>& histo_vect) {
|
||||||
|
assert(img.type() == CV_8UC3);
|
||||||
|
|
||||||
|
vector<Mat> 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<Vec3b>(canvas.rows - 1 - i, j + pad)[channel] = j;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
canvas.at<Vec3b>(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<int>(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<cv::Mat> histos, vector<cv::Mat>& 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<Mat> histos;
|
||||||
|
Histo::calcHistoC3(img, histos);
|
||||||
|
|
||||||
|
vector<Mat> canvases;
|
||||||
|
Histo::drawHistoC3(histos, canvases);
|
||||||
|
|
||||||
|
string str = "BGR";
|
||||||
|
for (int i = 0; i <= 2; ++i) {
|
||||||
|
imshow(title + "-" + str[i], canvases[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
waitKey(wait);
|
||||||
|
}
|
||||||
32
ora7/proj2/histo.h
Normal file
@@ -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 <vector>
|
||||||
|
#include <opencv2/core.hpp>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace cv;
|
||||||
|
|
||||||
|
namespace Histo {
|
||||||
|
void calcHistoC1(const cv::Mat img, cv::Mat& histo);
|
||||||
|
void calcHistoC3(const cv::Mat img, vector<cv::Mat>& histo);
|
||||||
|
|
||||||
|
void drawHistoC1(const cv::Mat histo, cv::Mat& canvas, int channel = -1);
|
||||||
|
void drawHistoC3(const vector<cv::Mat> histos, vector<cv::Mat>& canvases);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Egy kep hisztogramjanak megjelenitese.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="img">1 vagy 3 csatornas input kep</param>
|
||||||
|
/// <param name="title">ablaknev</param>
|
||||||
|
/// <param name="wait">varakoztatas</param>
|
||||||
|
void showHisto(Mat img, string title = "histo", int wait = 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif HISTO_H_
|
||||||
30
ora7/proj2/main.cpp
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
#include "histo.h"
|
||||||
|
#include "opencv2/core/types.hpp"
|
||||||
|
#include <opencv2/core.hpp>
|
||||||
|
#include <opencv2/highgui.hpp>
|
||||||
|
#include <opencv2/imgproc.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
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<std::vector<Point>> 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;
|
||||||
|
}
|
||||||
2
ora7/proj3/.clangd
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
CompileFlags:
|
||||||
|
Add: [-I/usr/include/opencv4, -std=c++17]
|
||||||
18
ora7/proj3/Makefile
Normal file
@@ -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)
|
||||||
126
ora7/proj3/histo.cpp
Normal file
@@ -0,0 +1,126 @@
|
|||||||
|
/*
|
||||||
|
Kepfeld. gyak. - nehany segedfuggveny az orai anyag konnyebb szemleltetesehez.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <opencv2/core.hpp>
|
||||||
|
#include <opencv2/imgproc.hpp>
|
||||||
|
#include <opencv2/highgui.hpp>
|
||||||
|
#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<int>(img.at<uchar>(i, j))++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Histo::calcHistoC3(const cv::Mat img, vector<cv::Mat>& histo_vect) {
|
||||||
|
assert(img.type() == CV_8UC3);
|
||||||
|
|
||||||
|
vector<Mat> 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<Vec3b>(canvas.rows - 1 - i, j + pad)[channel] = j;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
canvas.at<Vec3b>(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<int>(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<cv::Mat> histos, vector<cv::Mat>& 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<Mat> histos;
|
||||||
|
Histo::calcHistoC3(img, histos);
|
||||||
|
|
||||||
|
vector<Mat> canvases;
|
||||||
|
Histo::drawHistoC3(histos, canvases);
|
||||||
|
|
||||||
|
string str = "BGR";
|
||||||
|
for (int i = 0; i <= 2; ++i) {
|
||||||
|
imshow(title + "-" + str[i], canvases[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
waitKey(wait);
|
||||||
|
}
|
||||||
32
ora7/proj3/histo.h
Normal file
@@ -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 <vector>
|
||||||
|
#include <opencv2/core.hpp>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace cv;
|
||||||
|
|
||||||
|
namespace Histo {
|
||||||
|
void calcHistoC1(const cv::Mat img, cv::Mat& histo);
|
||||||
|
void calcHistoC3(const cv::Mat img, vector<cv::Mat>& histo);
|
||||||
|
|
||||||
|
void drawHistoC1(const cv::Mat histo, cv::Mat& canvas, int channel = -1);
|
||||||
|
void drawHistoC3(const vector<cv::Mat> histos, vector<cv::Mat>& canvases);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Egy kep hisztogramjanak megjelenitese.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="img">1 vagy 3 csatornas input kep</param>
|
||||||
|
/// <param name="title">ablaknev</param>
|
||||||
|
/// <param name="wait">varakoztatas</param>
|
||||||
|
void showHisto(Mat img, string title = "histo", int wait = 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif HISTO_H_
|
||||||
34
ora7/proj3/main.cpp
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#include "histo.h"
|
||||||
|
#include "opencv2/core/types.hpp"
|
||||||
|
#include <cassert>
|
||||||
|
#include <opencv2/core.hpp>
|
||||||
|
#include <opencv2/highgui.hpp>
|
||||||
|
#include <opencv2/imgproc.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
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<std::vector<Point>> 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;
|
||||||
|
}
|
||||||
2
ora7/proj4/.clangd
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
CompileFlags:
|
||||||
|
Add: [-I/usr/include/opencv4, -std=c++17]
|
||||||
18
ora7/proj4/Makefile
Normal file
@@ -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)
|
||||||
126
ora7/proj4/histo.cpp
Normal file
@@ -0,0 +1,126 @@
|
|||||||
|
/*
|
||||||
|
Kepfeld. gyak. - nehany segedfuggveny az orai anyag konnyebb szemleltetesehez.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <opencv2/core.hpp>
|
||||||
|
#include <opencv2/imgproc.hpp>
|
||||||
|
#include <opencv2/highgui.hpp>
|
||||||
|
#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<int>(img.at<uchar>(i, j))++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Histo::calcHistoC3(const cv::Mat img, vector<cv::Mat>& histo_vect) {
|
||||||
|
assert(img.type() == CV_8UC3);
|
||||||
|
|
||||||
|
vector<Mat> 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<Vec3b>(canvas.rows - 1 - i, j + pad)[channel] = j;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
canvas.at<Vec3b>(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<int>(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<cv::Mat> histos, vector<cv::Mat>& 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<Mat> histos;
|
||||||
|
Histo::calcHistoC3(img, histos);
|
||||||
|
|
||||||
|
vector<Mat> canvases;
|
||||||
|
Histo::drawHistoC3(histos, canvases);
|
||||||
|
|
||||||
|
string str = "BGR";
|
||||||
|
for (int i = 0; i <= 2; ++i) {
|
||||||
|
imshow(title + "-" + str[i], canvases[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
waitKey(wait);
|
||||||
|
}
|
||||||
32
ora7/proj4/histo.h
Normal file
@@ -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 <vector>
|
||||||
|
#include <opencv2/core.hpp>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace cv;
|
||||||
|
|
||||||
|
namespace Histo {
|
||||||
|
void calcHistoC1(const cv::Mat img, cv::Mat& histo);
|
||||||
|
void calcHistoC3(const cv::Mat img, vector<cv::Mat>& histo);
|
||||||
|
|
||||||
|
void drawHistoC1(const cv::Mat histo, cv::Mat& canvas, int channel = -1);
|
||||||
|
void drawHistoC3(const vector<cv::Mat> histos, vector<cv::Mat>& canvases);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Egy kep hisztogramjanak megjelenitese.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="img">1 vagy 3 csatornas input kep</param>
|
||||||
|
/// <param name="title">ablaknev</param>
|
||||||
|
/// <param name="wait">varakoztatas</param>
|
||||||
|
void showHisto(Mat img, string title = "histo", int wait = 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif HISTO_H_
|
||||||
42
ora7/proj4/main.cpp
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
#include "histo.h"
|
||||||
|
#include "opencv2/core/types.hpp"
|
||||||
|
#include <cassert>
|
||||||
|
#include <opencv2/core.hpp>
|
||||||
|
#include <opencv2/highgui.hpp>
|
||||||
|
#include <opencv2/imgproc.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
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<std::vector<Point>> 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;
|
||||||
|
}
|
||||||
2
ora7/proj5/.clangd
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
CompileFlags:
|
||||||
|
Add: [-I/usr/include/opencv4, -std=c++17]
|
||||||
18
ora7/proj5/Makefile
Normal file
@@ -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)
|
||||||
126
ora7/proj5/histo.cpp
Normal file
@@ -0,0 +1,126 @@
|
|||||||
|
/*
|
||||||
|
Kepfeld. gyak. - nehany segedfuggveny az orai anyag konnyebb szemleltetesehez.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <opencv2/core.hpp>
|
||||||
|
#include <opencv2/imgproc.hpp>
|
||||||
|
#include <opencv2/highgui.hpp>
|
||||||
|
#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<int>(img.at<uchar>(i, j))++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Histo::calcHistoC3(const cv::Mat img, vector<cv::Mat>& histo_vect) {
|
||||||
|
assert(img.type() == CV_8UC3);
|
||||||
|
|
||||||
|
vector<Mat> 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<Vec3b>(canvas.rows - 1 - i, j + pad)[channel] = j;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
canvas.at<Vec3b>(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<int>(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<cv::Mat> histos, vector<cv::Mat>& 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<Mat> histos;
|
||||||
|
Histo::calcHistoC3(img, histos);
|
||||||
|
|
||||||
|
vector<Mat> canvases;
|
||||||
|
Histo::drawHistoC3(histos, canvases);
|
||||||
|
|
||||||
|
string str = "BGR";
|
||||||
|
for (int i = 0; i <= 2; ++i) {
|
||||||
|
imshow(title + "-" + str[i], canvases[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
waitKey(wait);
|
||||||
|
}
|
||||||
32
ora7/proj5/histo.h
Normal file
@@ -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 <vector>
|
||||||
|
#include <opencv2/core.hpp>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace cv;
|
||||||
|
|
||||||
|
namespace Histo {
|
||||||
|
void calcHistoC1(const cv::Mat img, cv::Mat& histo);
|
||||||
|
void calcHistoC3(const cv::Mat img, vector<cv::Mat>& histo);
|
||||||
|
|
||||||
|
void drawHistoC1(const cv::Mat histo, cv::Mat& canvas, int channel = -1);
|
||||||
|
void drawHistoC3(const vector<cv::Mat> histos, vector<cv::Mat>& canvases);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Egy kep hisztogramjanak megjelenitese.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="img">1 vagy 3 csatornas input kep</param>
|
||||||
|
/// <param name="title">ablaknev</param>
|
||||||
|
/// <param name="wait">varakoztatas</param>
|
||||||
|
void showHisto(Mat img, string title = "histo", int wait = 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif HISTO_H_
|
||||||
42
ora7/proj5/main.cpp
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
#include "histo.h"
|
||||||
|
#include "opencv2/core/types.hpp"
|
||||||
|
#include <cassert>
|
||||||
|
#include <opencv2/core.hpp>
|
||||||
|
#include <opencv2/highgui.hpp>
|
||||||
|
#include <opencv2/imgproc.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
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<std::vector<Point>> 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;
|
||||||
|
}
|
||||||
BIN
ora7/rubber_pads.png
Normal file
|
After Width: | Height: | Size: 113 KiB |
BIN
ora7/sajt.png
Normal file
|
After Width: | Height: | Size: 690 KiB |
BIN
ora7/some_objects.png
Normal file
|
After Width: | Height: | Size: 6.4 KiB |
BIN
ora7/soybean_leafminer.jpg
Normal file
|
After Width: | Height: | Size: 166 KiB |
BIN
ora7/szita.jpg
Normal file
|
After Width: | Height: | Size: 438 KiB |