added clangd to dirs, fixed a name bug
@@ -16,7 +16,6 @@ int main(){
|
|||||||
Mat mask(img.rows, img.cols, CV_8UC1);
|
Mat mask(img.rows, img.cols, CV_8UC1);
|
||||||
Mat mask2 = Mat::zeros(img.size(), CV_8UC1); //kinullazot (fekete) mask (vagy barmi mas kep)
|
Mat mask2 = Mat::zeros(img.size(), CV_8UC1); //kinullazot (fekete) mask (vagy barmi mas kep)
|
||||||
|
|
||||||
|
|
||||||
//masolat
|
//masolat
|
||||||
Mat copy = img.clone(); //deepcopy
|
Mat copy = img.clone(); //deepcopy
|
||||||
//copy.setTo(Scalar(255,0,0)); //shallow copy -> changes original
|
//copy.setTo(Scalar(255,0,0)); //shallow copy -> changes original
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
using namespace cv;
|
using namespace cv;
|
||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
Mat img = imread("../KossuthSquare/SnapShot-20180731_173715.jpg.png"/*, IMREAD_COLOR*/);
|
Mat img = imread("../KossuthSquare/SnapShot-20180731_173715.jpg"/*, IMREAD_COLOR*/);
|
||||||
Mat acc = Mat::zeros(img.size(), CV_64FC3);
|
Mat acc = Mat::zeros(img.size(), CV_64FC3);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ int calc_th(Mat img, float fg_ratio = 0.1f){
|
|||||||
int main(){
|
int main(){
|
||||||
Mat img = imread("../scanned3.png", IMREAD_GRAYSCALE);
|
Mat img = imread("../scanned3.png", IMREAD_GRAYSCALE);
|
||||||
int th = calc_th(img, 0.1f);
|
int th = calc_th(img, 0.1f);
|
||||||
|
imshow("t", img);
|
||||||
Mat mask;
|
Mat mask;
|
||||||
if(th != -1){
|
if(th != -1){
|
||||||
threshold(img, mask, th, 255, THRESH_BINARY);
|
threshold(img, mask, th, 255, THRESH_BINARY);
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 646 KiB |
@@ -1,18 +0,0 @@
|
|||||||
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)
|
|
||||||
|
Before Width: | Height: | Size: 43 KiB |
|
Before Width: | Height: | Size: 259 KiB |
BIN
ora6/galaxy.jpg
|
Before Width: | Height: | Size: 12 KiB |
BIN
ora6/go2.png
|
Before Width: | Height: | Size: 997 KiB |
BIN
ora6/graycat.jpg
|
Before Width: | Height: | Size: 5.1 KiB |
BIN
ora6/hela.zip
BIN
ora6/hela/0.png
|
Before Width: | Height: | Size: 39 KiB |
BIN
ora6/hela/1.png
|
Before Width: | Height: | Size: 42 KiB |
BIN
ora6/hela/2.png
|
Before Width: | Height: | Size: 43 KiB |
BIN
ora6/hela/3.png
|
Before Width: | Height: | Size: 42 KiB |
BIN
ora6/hela/4.png
|
Before Width: | Height: | Size: 42 KiB |
BIN
ora6/hela/5.png
|
Before Width: | Height: | Size: 42 KiB |
BIN
ora6/hela/6.png
|
Before Width: | Height: | Size: 42 KiB |
BIN
ora6/hela/7.png
|
Before Width: | Height: | Size: 42 KiB |
BIN
ora6/hela/8.png
|
Before Width: | Height: | Size: 42 KiB |
BIN
ora6/hela/9.png
|
Before Width: | Height: | Size: 42 KiB |
126
ora6/histo.cpp
@@ -1,126 +0,0 @@
|
|||||||
/*
|
|
||||||
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
ora6/histo.h
@@ -1,32 +0,0 @@
|
|||||||
/*
|
|
||||||
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_
|
|
||||||
|
Before Width: | Height: | Size: 762 KiB |
@@ -1,26 +0,0 @@
|
|||||||
#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;
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
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)
|
|
||||||
@@ -1,126 +0,0 @@
|
|||||||
/*
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
/*
|
|
||||||
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_
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
#include "histo.h"
|
|
||||||
#include "opencv2/imgcodecs.hpp"
|
|
||||||
#include <opencv2/core.hpp>
|
|
||||||
#include <opencv2/highgui.hpp>
|
|
||||||
#include <opencv2/imgproc.hpp>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
using namespace cv;
|
|
||||||
|
|
||||||
void thinning(const Mat img, Mat& skel){
|
|
||||||
Mat mask, se, eroded, tmp;
|
|
||||||
mask = img.clone();
|
|
||||||
|
|
||||||
se = Mat::zeros(img.size(), CV_8UC1);
|
|
||||||
se = getStructuringElement(MORPH_CROSS, Size(3,3));
|
|
||||||
|
|
||||||
while(true){
|
|
||||||
erode(mask, eroded, se);
|
|
||||||
dilate(eroded, tmp, se);
|
|
||||||
tmp = mask - tmp;
|
|
||||||
skel = skel | tmp;
|
|
||||||
eroded.copyTo(mask); //shallow copy miatt kulonben csak a fejlecet masolja
|
|
||||||
|
|
||||||
if(countNonZero(mask) == 0){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
imshow("mask", mask);
|
|
||||||
imshow("skel", skel);
|
|
||||||
waitKey(100);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
Mat img = imread("../wrench.jpg", IMREAD_GRAYSCALE);
|
|
||||||
Mat mask, skel;
|
|
||||||
|
|
||||||
threshold(img, mask, 80, 255, THRESH_BINARY_INV);
|
|
||||||
//medianBlur(mask, mask, 7);
|
|
||||||
thinning(mask, skel);
|
|
||||||
|
|
||||||
imshow("mask", mask);
|
|
||||||
|
|
||||||
waitKey(0);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
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)
|
|
||||||
@@ -1,126 +0,0 @@
|
|||||||
/*
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
/*
|
|
||||||
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_
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
#include "histo.h"
|
|
||||||
#include "opencv2/imgcodecs.hpp"
|
|
||||||
#include <opencv2/core.hpp>
|
|
||||||
#include <opencv2/highgui.hpp>
|
|
||||||
#include <opencv2/imgproc.hpp>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
using namespace cv;
|
|
||||||
|
|
||||||
void Roberts(const Mat& img){
|
|
||||||
Mat g, gx, gy, g2, edge, edge2;
|
|
||||||
gx = Mat::zeros(img.size(), CV_16S);
|
|
||||||
gy = Mat::zeros(img.size(), CV_16S);
|
|
||||||
|
|
||||||
for (int i = 0; i < img.rows -1; i++) {
|
|
||||||
for (int j = 0; j < img.cols -1; j++) {
|
|
||||||
gx.at<short>(i,j) = img.at<uchar>(i,j) - img.at<uchar>(i+1, j+1);
|
|
||||||
gy.at<short>(i,j) = img.at<uchar>(i,j+1) - img.at<uchar>(i+1, j);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
g = cv::abs(gx) + cv::abs(gy);
|
|
||||||
|
|
||||||
convertScaleAbs(g, g2);
|
|
||||||
|
|
||||||
threshold(g2, edge, 0, 255, THRESH_OTSU);
|
|
||||||
threshold(g2, edge2, 0, 255, THRESH_TRIANGLE);
|
|
||||||
|
|
||||||
imshow("edge", edge);
|
|
||||||
imshow("edg2", edge2);
|
|
||||||
|
|
||||||
//imshow("g", g * 255);
|
|
||||||
//imshow("gx", gx * 255);
|
|
||||||
//imshow("gy", gy * 255);
|
|
||||||
}
|
|
||||||
|
|
||||||
void sobel(const Mat img){
|
|
||||||
Mat g, g2, gx, gy;
|
|
||||||
|
|
||||||
Sobel(img, gx, CV_32F, 1,0);
|
|
||||||
Sobel(img, gy, CV_32F, 0,1);
|
|
||||||
|
|
||||||
|
|
||||||
//g = cv::abs(gx) + cv::abs(gy);
|
|
||||||
//cv::sqrt(gx.mul(gx) + gy.mul(gy));
|
|
||||||
convertScaleAbs(g, g2);
|
|
||||||
//imshow("gx", gx / 255);
|
|
||||||
//imshow("gx", gy / 255);
|
|
||||||
//imshow("g2", g2);
|
|
||||||
|
|
||||||
Mat dest;
|
|
||||||
Laplacian(img, dest, CV_16S, 3);
|
|
||||||
convertScaleAbs(dest, dest);
|
|
||||||
imshow("dest", dest);
|
|
||||||
|
|
||||||
waitKey(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
Mat img = imread("../go2.png", IMREAD_GRAYSCALE);
|
|
||||||
imshow("ered", img);
|
|
||||||
//Roberts(img);
|
|
||||||
sobel(img);
|
|
||||||
|
|
||||||
while(waitKey(3) != 'q');
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
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)
|
|
||||||
@@ -1,126 +0,0 @@
|
|||||||
/*
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
/*
|
|
||||||
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_
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
#include "histo.h"
|
|
||||||
#include <opencv2/core.hpp>
|
|
||||||
#include <opencv2/highgui.hpp>
|
|
||||||
#include <opencv2/imgproc.hpp>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
using namespace cv;
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
|
|
||||||
|
|
||||||
waitKey();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
CompileFlags:
|
|
||||||
Add: [-I/usr/include/opencv4, -std=c++17]
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
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)
|
|
||||||
@@ -1,126 +0,0 @@
|
|||||||
/*
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
/*
|
|
||||||
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_
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
#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;
|
|
||||||
}
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
CompileFlags:
|
|
||||||
Add: [-I/usr/include/opencv4, -std=c++17]
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
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)
|
|
||||||
@@ -1,126 +0,0 @@
|
|||||||
/*
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
/*
|
|
||||||
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_
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
#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
ora6/road.png
|
Before Width: | Height: | Size: 892 KiB |
BIN
ora6/sajt.png
|
Before Width: | Height: | Size: 690 KiB |
|
Before Width: | Height: | Size: 179 KiB |
|
Before Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 394 KiB |
|
Before Width: | Height: | Size: 188 KiB |
BIN
ora6/wrench.jpg
|
Before Width: | Height: | Size: 96 KiB |