Last active
March 5, 2020 20:59
-
-
Save BernardoGO/b7939a1a53691f28a0a9985e6272d2eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
g++ main.cpp -o output `pkg-config --cflags --libs opencv` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <opencv2/highgui.hpp> | |
#include "opencv2/imgproc/imgproc.hpp" | |
#include <iostream> | |
int main( int argc, char** argv ) { | |
//Carregar imagem de entrada | |
cv::Mat img = cv::imread("sample.png" , CV_LOAD_IMAGE_COLOR); | |
cv::cvtColor( img, img, cv::COLOR_BGR2GRAY ); | |
//Criando o Kernel 3x3 de 1/9 para boxblur | |
cv::Mat kernel = (cv::Mat_<float>(3, 3, CV_32F) << 1, 1, 1, | |
1, 1, 1, | |
1, 1, 1) / (float)9; | |
//Aplica a convolução sobre a imagem | |
cv::filter2D(img, img, -1 , kernel, cv::Point( -1, -1 ), 0, cv::BORDER_DEFAULT ); | |
//Salva a imagem de saída | |
cv::imwrite( "boxblur.jpg", img ); | |
// Exibir imagem de saída em janela | |
cv::namedWindow( "Display window", cv::WINDOW_AUTOSIZE ); | |
cv::imshow( "Display window", img ); | |
cv::waitKey(0); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <opencv2/highgui.hpp> | |
#include "opencv2/imgproc/imgproc.hpp" | |
#include <iostream> | |
int main( int argc, char** argv ) { | |
//Carregar imagem de entrada | |
cv::Mat img = cv::imread("sample.png" , CV_LOAD_IMAGE_COLOR); | |
cv::cvtColor( img, img, cv::COLOR_BGR2GRAY ); | |
//Criando o Kernel 5x5 para Sharpening | |
cv::Mat kernel = (cv::Mat_<float>(5, 5, CV_32F) << -1, -1, -1, -1, -1, | |
-1, -1, -1, -1, -1, | |
-1, -1, 25, -1, -1, | |
-1, -1, -1, -1, -1, | |
-1, -1, -1, -1, -1 | |
); | |
//Aplica a convolução sobre a imagem | |
cv::filter2D(img, img, -1 , kernel, cv::Point( -1, -1 ), 0, cv::BORDER_DEFAULT ); | |
//Salva a imagem de saída | |
cv::imwrite( "sharpening.jpg", img ); | |
// Exibir imagem de saída em janela | |
cv::namedWindow( "Display window", cv::WINDOW_AUTOSIZE ); | |
cv::imshow( "Display window", img ); | |
cv::waitKey(0); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <opencv2/highgui.hpp> | |
#include "opencv2/imgproc/imgproc.hpp" | |
#include <iostream> | |
int main( int argc, char** argv ) { | |
//Carregar imagem de entrada | |
cv::Mat img = cv::imread("sample.png" , CV_LOAD_IMAGE_COLOR); | |
// Converte imagem para tons de | |
cv::cvtColor( img, img, cv::COLOR_BGR2GRAY ); | |
// Limiarização binária de 64 para 255. | |
cv::threshold(img,img, 64, 255, cv::THRESH_BINARY); | |
//Salva a imagem de saída | |
cv::imwrite( "output.jpg", img ); | |
// Exibir imagem de saída em janela | |
cv::namedWindow( "Display window", cv::WINDOW_AUTOSIZE ); | |
cv::imshow( "Display window", img ); | |
cv::waitKey(0); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <opencv2/highgui.hpp> | |
#include <iostream> | |
int main( int argc, char** argv ) { | |
//Carregar imagem de entrada | |
cv::Mat img = cv::imread("sample.jpeg" , CV_LOAD_IMAGE_COLOR); | |
for (int i = 0; i < img.rows; ++i) //Loop pelas linhas da imagem | |
{ | |
// Primeiro pixel da linha atual | |
cv::Vec3b* pixel = img.ptr<cv::Vec3b>(i); | |
for (int j = 0; j < img.cols; ++j) //Loop pelas colunas da imagem | |
{ | |
//Inverte cada um dos três (R,G,B) canais da imagem com operador `not` | |
pixel[j][2] = ~pixel[j][2]; | |
pixel[j][1] = ~pixel[j][1]; | |
pixel[j][0] = ~pixel[j][0]; | |
} | |
} | |
//Exibir imagem de saída em janela | |
cv::namedWindow( "Display window", cv::WINDOW_AUTOSIZE ); | |
cv::imshow( "Display window", img ); | |
cv::waitKey(0); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment