final
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 |