fixed clangd, ora5
BIN
ora5/Képek (küszöbölés)-20251009.zip
Normal file
18
ora5/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
ora5/black_bear.jpg
Normal file
|
After Width: | Height: | Size: 5.2 KiB |
BIN
ora5/coins.png
Normal file
|
After Width: | Height: | Size: 72 KiB |
BIN
ora5/dog.jpg
Normal file
|
After Width: | Height: | Size: 7.9 KiB |
BIN
ora5/gray_buttons.jpg
Normal file
|
After Width: | Height: | Size: 26 KiB |
126
ora5/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
ora5/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_
|
||||
BIN
ora5/madar.jpg
Normal file
|
After Width: | Height: | Size: 6.9 KiB |
26
ora5/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
ora5/melanoma.jpg
Normal file
|
After Width: | Height: | Size: 194 KiB |
2
ora5/proj1/.clangd
Normal file
@@ -0,0 +1,2 @@
|
||||
CompileFlags:
|
||||
Add: [-I/usr/include/opencv4, -std=c++17]
|
||||
18
ora5/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
ora5/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
ora5/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_
|
||||
45
ora5/proj1/main.cpp
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;
|
||||
}
|
||||
2
ora5/proj2/.clangd
Normal file
@@ -0,0 +1,2 @@
|
||||
CompileFlags:
|
||||
Add: [-I/usr/include/opencv4, -std=c++17]
|
||||
18
ora5/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
ora5/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
ora5/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_
|
||||
22
ora5/proj2/main.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#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("../gray_buttons.jpg", IMREAD_GRAYSCALE);
|
||||
imshow("img", img);
|
||||
Histo::showHisto(img);
|
||||
|
||||
Mat dest1, dest2, dest3, dest4, mask;
|
||||
inRange(img, 165, 213, mask);
|
||||
medianBlur(mask, mask, 7);
|
||||
|
||||
imshow("res", mask);
|
||||
|
||||
while(waitKey(3) != 'q');
|
||||
return 0;
|
||||
}
|
||||
2
ora5/proj3/.clangd
Normal file
@@ -0,0 +1,2 @@
|
||||
CompileFlags:
|
||||
Add: [-I/usr/include/opencv4, -std=c++17]
|
||||
18
ora5/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
ora5/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
ora5/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_
|
||||
43
ora5/proj3/main.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include "histo.h"
|
||||
#include "opencv2/videoio.hpp"
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <iostream>
|
||||
|
||||
using namespace cv;
|
||||
|
||||
int main(){
|
||||
VideoCapture cap("../sas.avi");
|
||||
|
||||
if(!cap.isOpened()){
|
||||
std::cout << "no video" << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
Mat img, gray, skymask, clone;
|
||||
|
||||
while(true){
|
||||
cap >> img; //kiolvas egy kepkockat
|
||||
|
||||
if(img.empty()){
|
||||
break; //video vege vagy serult
|
||||
}
|
||||
|
||||
//imshow("img", img);
|
||||
cvtColor(img, gray, COLOR_BGR2GRAY);
|
||||
|
||||
inRange(gray, 100, 160, skymask);
|
||||
//imshow("skymask", skymask);
|
||||
|
||||
clone = img.clone(); //teljesen fuggetlen az eredeti keptol
|
||||
clone.setTo(Scalar(0,0,0), skymask);
|
||||
imshow("clone", clone);
|
||||
|
||||
waitKey(60);
|
||||
}
|
||||
|
||||
|
||||
waitKey();
|
||||
return 0;
|
||||
}
|
||||
2
ora5/proj4/.clangd
Normal file
@@ -0,0 +1,2 @@
|
||||
CompileFlags:
|
||||
Add: [-I/usr/include/opencv4, -std=c++17]
|
||||
18
ora5/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
ora5/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
ora5/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
ora5/proj4/main.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
#include "histo.h"
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/videoio.hpp"
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <iostream>
|
||||
|
||||
using namespace cv;
|
||||
|
||||
int calc_th(Mat img, float fg_ratio = 0.1f){
|
||||
int nfg = img.cols * img.rows * fg_ratio;
|
||||
Mat histo;
|
||||
Histo::calcHistoC1(img, histo);
|
||||
|
||||
double s = 0;
|
||||
int th = 0;
|
||||
|
||||
for(; th < 256; th++){
|
||||
s += histo.at<int>(th);
|
||||
if(s >= nfg){
|
||||
return th;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int main(){
|
||||
Mat img = imread("../scanned3.png", IMREAD_GRAYSCALE);
|
||||
int th = calc_th(img, 0.1f);
|
||||
|
||||
Mat mask;
|
||||
if(th != -1){
|
||||
threshold(img, mask, th, 255, THRESH_BINARY);
|
||||
imshow("img2", mask);
|
||||
}
|
||||
|
||||
while(waitKey(3) != 'q');
|
||||
return 0;
|
||||
}
|
||||
BIN
ora5/retina.jpg
Normal file
|
After Width: | Height: | Size: 849 KiB |
BIN
ora5/sand.png
Normal file
|
After Width: | Height: | Size: 142 KiB |
BIN
ora5/sas.avi
Normal file
BIN
ora5/scanned3.png
Normal file
|
After Width: | Height: | Size: 677 KiB |
BIN
ora5/sejt1.jpg
Normal file
|
After Width: | Height: | Size: 230 KiB |
BIN
ora5/sejtek.png
Normal file
|
After Width: | Height: | Size: 770 KiB |
BIN
ora5/zh.jpg
Normal file
|
After Width: | Height: | Size: 318 KiB |