Complete C++ Program Pdf......As because this document does not contain any theory so kindly feel free to ask if have any doubt or problem.
Happy to help. Thanks
Complete C++ Program Pdf......As because this document does not contain any theory so kindly feel free to ask if have any doubt or problem.
Happy to help. Thanks
Story of static code analyzer developmentAndrey Karpov
Greetings from the past: simple tools and bad standards. Regular expressions don’t work. What is inside modern static code analyzers on the PVS-Studio example. About machine learning. Learning vs Data Flow analysis.
PVS-Studio team experience: checking various open source projects, or mistake...Andrey Karpov
To let the world know about our product, we check open-source projects. By the moment we have checked 245 projects. A side effect: we found 9574 errors and notified the authors about them.
C++ How I learned to stop worrying and love metaprogrammingcppfrug
Cette présentation parcours quelques applications directes de la méta-programmation en C++(11/14) avec comme objectif de démontrer son utilité dans un cadre applicatif.
C++ open positions and popularity remain high as media has recently, and there is a reason for that: from the many languages and platforms that developers have available today, C++ features uncontested capabilities in power and performance, allowing innovation outside the box (just think on action games, natural user interfaces or augmented reality, to mention some). In this talk you’ll see the new features and technologies that are coming with Visual C++ vNext, helping you build compelling applications with a renewed developer experience. Don’t miss it!!
Gor Nishanov, C++ Coroutines – a negative overhead abstractionSergey Platonov
C++ coroutines are one of the few major features that may land in C++17. We will look at the current standardization status, available experimental implementations and develop a small coroutine adapter over raw C networking APIs that will beat hand-crafted state machine in performance.
Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014PyData
Pythran is a an ahead of time compiler that turns modules written in a large subset of Python into C++ meta-programs that can be compiled into efficient native modules. It targets mainly compute intensive part of the code, hence it comes as no surprise that it focuses on scientific applications that makes extensive use of Numpy. Under the hood, Pythran inter-procedurally analyses the program and performs high level optimizations and parallel code generation. Parallelism can be found implicitly in Python intrinsics or Numpy operations, or explicitly specified by the programmer using OpenMP directives directly in the Python source code. Either way, the input code remains fully compatible with the Python interpreter. While the idea is similar to Parakeet or Numba, the approach differs significantly: the code generation is not performed at runtime but offline. Pythran generates C++11 heavily templated code that makes use of the NT2 meta-programming library and relies on any standard-compliant compiler to generate the binary code. We propose to walk through some examples and benchmarks, exposing the current state of what Pythran provides as well as the limit of the approach.
Presentation from DICE Coder's Day (2010 November) by Johan Torp:
This talk is about making object-oriented code more cache-friendly and how we can incrementally move towards parallelizable data-oriented designs. Filled with production code examples from Frostbite’s pathfinding implementation.
In this talk I introduced Yampa, the AFRP framework in Haskell, and the Quake-like game made by it. The content convers the basic of Functional Reactive Programming, Haskell Arrow, Yampa itself, time-space leak, etc.
Story of static code analyzer developmentAndrey Karpov
Greetings from the past: simple tools and bad standards. Regular expressions don’t work. What is inside modern static code analyzers on the PVS-Studio example. About machine learning. Learning vs Data Flow analysis.
PVS-Studio team experience: checking various open source projects, or mistake...Andrey Karpov
To let the world know about our product, we check open-source projects. By the moment we have checked 245 projects. A side effect: we found 9574 errors and notified the authors about them.
C++ How I learned to stop worrying and love metaprogrammingcppfrug
Cette présentation parcours quelques applications directes de la méta-programmation en C++(11/14) avec comme objectif de démontrer son utilité dans un cadre applicatif.
C++ open positions and popularity remain high as media has recently, and there is a reason for that: from the many languages and platforms that developers have available today, C++ features uncontested capabilities in power and performance, allowing innovation outside the box (just think on action games, natural user interfaces or augmented reality, to mention some). In this talk you’ll see the new features and technologies that are coming with Visual C++ vNext, helping you build compelling applications with a renewed developer experience. Don’t miss it!!
Gor Nishanov, C++ Coroutines – a negative overhead abstractionSergey Platonov
C++ coroutines are one of the few major features that may land in C++17. We will look at the current standardization status, available experimental implementations and develop a small coroutine adapter over raw C networking APIs that will beat hand-crafted state machine in performance.
Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014PyData
Pythran is a an ahead of time compiler that turns modules written in a large subset of Python into C++ meta-programs that can be compiled into efficient native modules. It targets mainly compute intensive part of the code, hence it comes as no surprise that it focuses on scientific applications that makes extensive use of Numpy. Under the hood, Pythran inter-procedurally analyses the program and performs high level optimizations and parallel code generation. Parallelism can be found implicitly in Python intrinsics or Numpy operations, or explicitly specified by the programmer using OpenMP directives directly in the Python source code. Either way, the input code remains fully compatible with the Python interpreter. While the idea is similar to Parakeet or Numba, the approach differs significantly: the code generation is not performed at runtime but offline. Pythran generates C++11 heavily templated code that makes use of the NT2 meta-programming library and relies on any standard-compliant compiler to generate the binary code. We propose to walk through some examples and benchmarks, exposing the current state of what Pythran provides as well as the limit of the approach.
Presentation from DICE Coder's Day (2010 November) by Johan Torp:
This talk is about making object-oriented code more cache-friendly and how we can incrementally move towards parallelizable data-oriented designs. Filled with production code examples from Frostbite’s pathfinding implementation.
In this talk I introduced Yampa, the AFRP framework in Haskell, and the Quake-like game made by it. The content convers the basic of Functional Reactive Programming, Haskell Arrow, Yampa itself, time-space leak, etc.
/* Lab 2: Histrogram generation
* Author: Naga Kandasamy
* Date: 01/25/2017
*
* compile as follows: gcc -o histogram histogram.c -std=c99 -fopenmp -lm
*/
#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>
#include <math.h>
#include <float.h>
#include <omp.h>
void run_test(int);
void compute_gold(int *, int *, int, int);
void compute_using_openmp(int *, int *, int, int);
void check_histogram(int *, int, int);
#define HISTOGRAM_SIZE 500
#define NUM_THREADS 8
////////////////////////////////////////////////////////////////////////////////
// Program main
////////////////////////////////////////////////////////////////////////////////
int
main( int argc, char** argv)
{
if(argc != 2){
printf("Usage: histogram <num elements> \n");
exit(0);
}
int num_elements = atoi(argv[1]);
run_test(num_elements);
return 0;
}
////////////////////////////////////////////////////////////////////////////////
//! Generate the histogram in both single-threaded and multi-threaded fashion and compare results for correctness
////////////////////////////////////////////////////////////////////////////////
void run_test(int num_elements)
{
double diff;
int i;
int *reference_histogram = (int *)malloc(sizeof(int) * HISTOGRAM_SIZE); // Space to store histogram generated by the CPU
int *histogram_using_openmp = (int *)malloc(sizeof(int) * HISTOGRAM_SIZE); // Space to store histogram generated by the GPU
// Allocate memory for the input data
int size = sizeof(int) * num_elements;
int *input_data = (int *)malloc(size);
// Randomly generate input data. Initialize the input data to be integer values between 0 and (HISTOGRAM_SIZE - 1)
for(i = 0; i < num_elements; i++)
input_data[i] = floorf((HISTOGRAM_SIZE - 1) * (rand()/(float)RAND_MAX));
printf("Creating the reference histogram. \n");
// Compute the reference solution on the CPU
struct timeval start, stop;
gettimeofday(&start, NULL);
compute_gold(input_data, reference_histogram, num_elements, HISTOGRAM_SIZE);
gettimeofday(&stop, NULL);
printf("CPU run time = %0.2f s. \n", (float)(stop.tv_sec - start.tv_sec + (stop.tv_usec - start.tv_usec)/(float)1000000));
// check_histogram(reference_histogram, num_elements, HISTOGRAM_SIZE);
// Compute the histogram using openmp. The result histogram should be stored on the histogram_using_openmp array
printf("\n");
printf("Creating histogram using OpenMP. \n");
compute_using_openmp(input_data, histogram_using_openmp, num_elements, HISTOGRAM_SIZE);
// check_histogram(histogram_using_openmp, num_elements, HISTOGRAM_SIZE);
// Compute the differences between the reference and pthread results
diff = 0.0;
for(i = 0; i < HISTOGRAM_SIZE; i++)
diff = diff + abs(reference_histogram[i] - histogram_using_openmp[i]);
printf("Difference between the reference and OpenMP results: %f. \n", diff);
// cleanup memory
free(input_data);
free(reference_his ...
Lecture 4 from the COSC 426 graduate class on Augmented Reality. Taught by Mark Billinghurst from the HIT Lab NZ at the University of Canterbury. August 1st 2012
The X-Ray Engine is a game engine, used in the S.T.A.L.K.E.R. game series. Its code was made public in September 16 2014, and since then, STALKER fans continue its development. A large project size, and a huge number of bugs in the games, gives us a wonderful chance to show what PVS-Studio is capable of.
Flash over the years, has been used to prop up the regular browser like a sad old man drinking alone in a pub.
Today browsers come shipped with technology designed to rival flash and aim to shut it squarely out of the game.
Are browser ready to rock without Flash?
Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 2PVS-Studio
This is the second and last part of the large article about analysis of the Haiku operating system. In the first article, we discussed a variety of possible errors all of which one way or another deal with conditions. In this article, we will discuss the remaining analyzer warnings I have selected for you. The bug examples are grouped into several categories.
Tutorial Membuat Simple Crane Menggunakan CoppeliasimLusiana Diyan
oppeliaSim, sebelumnya dikenal sebagai V-REP, adalah simulator robot yang digunakan dalam industri, pendidikan dan penelitian .. Itu menggunakan perpustakaan simulasi fisika ODE, Bullet, Vortex dan Newton untuk melakukan simulasi benda kaku.
CRUD pada Android Studio menggunakan MySQLLusiana Diyan
MySQL adalah sebuah perangkat lunak sistem manajemen basis data SQL atau DBMS yang multialur, multipengguna, dengan sekitar 6 juta instalasi di seluruh dunia.
Internet of Thing (IoT) adalah sebuah konsep dimana suatu objek yang memiliki kemampuan untuk mentransfer data melalui jaringan tanpa memerlukan interaksi manusia ke manusia atau manusia ke komputer. IoT telah berkembang dari konvergensi teknologi nirkabel, micro-electromechanical systems (MEMS), dan Internet.
NodeMCU adalah platform IoT open source berbiaya rendah. Ini awalnya termasuk firmware yang berjalan pada ESP8266 Wi-Fi SoC dari Espressif Systems, dan perangkat keras yang didasarkan pada modul ESP-12. Kemudian, dukungan untuk MCU 32-bit ESP32 ditambahkan.
Raspberry Pi, sering disingkat dengan nama Raspi, adalah komputer papan tunggal yang seukuran dengan kartu kredit yang dapat digunakan untuk menjalankan program perkantoran, permainan komputer, dan sebagai pemutar media hingga video beresolusi tinggi.
CcoppeliaSim, sebelumnya dikenal sebagai V-REP, adalah simulator robot yang digunakan dalam industri, pendidikan dan penelitian .. Itu menggunakan perpustakaan simulasi fisika ODE, Bullet, Vortex dan Newton untuk melakukan simulasi benda kaku.
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Dr.Costas Sachpazis
Terzaghi's soil bearing capacity theory, developed by Karl Terzaghi, is a fundamental principle in geotechnical engineering used to determine the bearing capacity of shallow foundations. This theory provides a method to calculate the ultimate bearing capacity of soil, which is the maximum load per unit area that the soil can support without undergoing shear failure. The Calculation HTML Code included.
Explore the innovative world of trenchless pipe repair with our comprehensive guide, "The Benefits and Techniques of Trenchless Pipe Repair." This document delves into the modern methods of repairing underground pipes without the need for extensive excavation, highlighting the numerous advantages and the latest techniques used in the industry.
Learn about the cost savings, reduced environmental impact, and minimal disruption associated with trenchless technology. Discover detailed explanations of popular techniques such as pipe bursting, cured-in-place pipe (CIPP) lining, and directional drilling. Understand how these methods can be applied to various types of infrastructure, from residential plumbing to large-scale municipal systems.
Ideal for homeowners, contractors, engineers, and anyone interested in modern plumbing solutions, this guide provides valuable insights into why trenchless pipe repair is becoming the preferred choice for pipe rehabilitation. Stay informed about the latest advancements and best practices in the field.
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxR&R Consult
CFD analysis is incredibly effective at solving mysteries and improving the performance of complex systems!
Here's a great example: At a large natural gas-fired power plant, where they use waste heat to generate steam and energy, they were puzzled that their boiler wasn't producing as much steam as expected.
R&R and Tetra Engineering Group Inc. were asked to solve the issue with reduced steam production.
An inspection had shown that a significant amount of hot flue gas was bypassing the boiler tubes, where the heat was supposed to be transferred.
R&R Consult conducted a CFD analysis, which revealed that 6.3% of the flue gas was bypassing the boiler tubes without transferring heat. The analysis also showed that the flue gas was instead being directed along the sides of the boiler and between the modules that were supposed to capture the heat. This was the cause of the reduced performance.
Based on our results, Tetra Engineering installed covering plates to reduce the bypass flow. This improved the boiler's performance and increased electricity production.
It is always satisfying when we can help solve complex challenges like this. Do your systems also need a check-up or optimization? Give us a call!
Work done in cooperation with James Malloy and David Moelling from Tetra Engineering.
More examples of our work https://www.r-r-consult.dk/en/cases-en/
Water scarcity is the lack of fresh water resources to meet the standard water demand. There are two type of water scarcity. One is physical. The other is economic water scarcity.
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...Amil Baba Dawood bangali
Contact with Dawood Bhai Just call on +92322-6382012 and we'll help you. We'll solve all your problems within 12 to 24 hours and with 101% guarantee and with astrology systematic. If you want to take any personal or professional advice then also you can call us on +92322-6382012 , ONLINE LOVE PROBLEM & Other all types of Daily Life Problem's.Then CALL or WHATSAPP us on +92322-6382012 and Get all these problems solutions here by Amil Baba DAWOOD BANGALI
#vashikaranspecialist #astrologer #palmistry #amliyaat #taweez #manpasandshadi #horoscope #spiritual #lovelife #lovespell #marriagespell#aamilbabainpakistan #amilbabainkarachi #powerfullblackmagicspell #kalajadumantarspecialist #realamilbaba #AmilbabainPakistan #astrologerincanada #astrologerindubai #lovespellsmaster #kalajaduspecialist #lovespellsthatwork #aamilbabainlahore#blackmagicformarriage #aamilbaba #kalajadu #kalailam #taweez #wazifaexpert #jadumantar #vashikaranspecialist #astrologer #palmistry #amliyaat #taweez #manpasandshadi #horoscope #spiritual #lovelife #lovespell #marriagespell#aamilbabainpakistan #amilbabainkarachi #powerfullblackmagicspell #kalajadumantarspecialist #realamilbaba #AmilbabainPakistan #astrologerincanada #astrologerindubai #lovespellsmaster #kalajaduspecialist #lovespellsthatwork #aamilbabainlahore #blackmagicforlove #blackmagicformarriage #aamilbaba #kalajadu #kalailam #taweez #wazifaexpert #jadumantar #vashikaranspecialist #astrologer #palmistry #amliyaat #taweez #manpasandshadi #horoscope #spiritual #lovelife #lovespell #marriagespell#aamilbabainpakistan #amilbabainkarachi #powerfullblackmagicspell #kalajadumantarspecialist #realamilbaba #AmilbabainPakistan #astrologerincanada #astrologerindubai #lovespellsmaster #kalajaduspecialist #lovespellsthatwork #aamilbabainlahore #Amilbabainuk #amilbabainspain #amilbabaindubai #Amilbabainnorway #amilbabainkrachi #amilbabainlahore #amilbabaingujranwalan #amilbabainislamabad
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdfKamal Acharya
The College Bus Management system is completely developed by Visual Basic .NET Version. The application is connect with most secured database language MS SQL Server. The application is develop by using best combination of front-end and back-end languages. The application is totally design like flat user interface. This flat user interface is more attractive user interface in 2017. The application is gives more important to the system functionality. The application is to manage the student’s details, driver’s details, bus details, bus route details, bus fees details and more. The application has only one unit for admin. The admin can manage the entire application. The admin can login into the application by using username and password of the admin. The application is develop for big and small colleges. It is more user friendly for non-computer person. Even they can easily learn how to manage the application within hours. The application is more secure by the admin. The system will give an effective output for the VB.Net and SQL Server given as input to the system. The compiled java program given as input to the system, after scanning the program will generate different reports. The application generates the report for users. The admin can view and download the report of the data. The application deliver the excel format reports. Because, excel formatted reports is very easy to understand the income and expense of the college bus. This application is mainly develop for windows operating system users. In 2017, 73% of people enterprises are using windows operating system. So the application will easily install for all the windows operating system users. The application-developed size is very low. The application consumes very low space in disk. Therefore, the user can allocate very minimum local disk space for this application.
Event Management System Vb Net Project Report.pdfKamal Acharya
In present era, the scopes of information technology growing with a very fast .We do not see any are untouched from this industry. The scope of information technology has become wider includes: Business and industry. Household Business, Communication, Education, Entertainment, Science, Medicine, Engineering, Distance Learning, Weather Forecasting. Carrier Searching and so on.
My project named “Event Management System” is software that store and maintained all events coordinated in college. It also helpful to print related reports. My project will help to record the events coordinated by faculties with their Name, Event subject, date & details in an efficient & effective ways.
In my system we have to make a system by which a user can record all events coordinated by a particular faculty. In our proposed system some more featured are added which differs it from the existing system such as security.
Final project report on grocery store management system..pdfKamal Acharya
In today’s fast-changing business environment, it’s extremely important to be able to respond to client needs in the most effective and timely manner. If your customers wish to see your business online and have instant access to your products or services.
Online Grocery Store is an e-commerce website, which retails various grocery products. This project allows viewing various products available enables registered users to purchase desired products instantly using Paytm, UPI payment processor (Instant Pay) and also can place order by using Cash on Delivery (Pay Later) option. This project provides an easy access to Administrators and Managers to view orders placed using Pay Later and Instant Pay options.
In order to develop an e-commerce website, a number of Technologies must be studied and understood. These include multi-tiered architecture, server and client-side scripting techniques, implementation technologies, programming language (such as PHP, HTML, CSS, JavaScript) and MySQL relational databases. This is a project with the objective to develop a basic website where a consumer is provided with a shopping cart website and also to know about the technologies used to develop such a website.
This document will discuss each of the underlying technologies to create and implement an e- commerce website.
Vaccine management system project report documentation..pdfKamal Acharya
The Division of Vaccine and Immunization is facing increasing difficulty monitoring vaccines and other commodities distribution once they have been distributed from the national stores. With the introduction of new vaccines, more challenges have been anticipated with this additions posing serious threat to the already over strained vaccine supply chain system in Kenya.
1. LAPORAN WORKSHOP KOMPUTER VISI
HISTOGRAM dan SEGMENTASI
LUSIANA DIYAN NINGRUM
2210181051
3 D4 TEKNIK KOMPUTER B
PRODI SARJANA TERAPAN TEKNIK KOMPUTER
DEPARTEMEN TEKNIK INFORMATIKA DAN KOMPUTER
POLITEKNIK ELEKTRONIKA NEGERI SURABAYA
SURABAYA
2. Histogram Gray Scale Image dari Sebuah File
#include <opencv2opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
Mat frame, gray_frame;
frame = imread("histo3.JPG", CV_LOAD_IMAGE_COLOR); // Read the file
"image.jpg".
cvtColor(frame, gray_frame, COLOR_BGR2GRAY);
imshow("Gray Scale Image", gray_frame);
/// Establish the number of bins
int histSize = 256;
/// Set the ranges
float range[] = { 0, 256 };
const float* histRange = { range };
bool uniform = true; bool accumulate = false;
Mat b_hist;
/// Compute the histograms:
calcHist(&gray_frame, 1, 0, Mat(), b_hist, 1, &histSize, &histRange,
uniform, accumulate);
// Draw the histograms
int hist_w = 512; int hist_h = 400;
int bin_w = cvRound((double)hist_w / histSize);
Mat histImage(hist_h, hist_w, CV_8UC3, Scalar(0, 0, 0));
/// Normalize the result to [ 0, histImage.rows ]
normalize(b_hist, b_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());
/// Draw Histogram
for (int i = 1; i < histSize; i++)
{
line(histImage, Point(bin_w*(i - 1), hist_h -
cvRound(b_hist.at<float>(i - 1))),
Point(bin_w*(i), hist_h -
cvRound(b_hist.at<float>(i))),
Scalar(255, 0, 0), 2, 8, 0);
}
/// Display
imshow("Histogram of Gray Scale Image", histImage);
waitKey();
return EXIT_SUCCESS;
}
3. Image1
Image2
Image 3
Analisa
Berdasarkan hasil grafik image dapat diketahui bahwa semakin banyak bagian terang pada
suatu gambar, grafik akan cenderung tinggi di sebelah kanan, dan semakin banyak elemen
gelap dalam suatu gambar maka grafik akan cederung tinggi di sisi kiri. Hal ini dikarena
grafik di sebelah kiri merupakan warna hitam yang semakin ke kanan akan condong ke warna
putih, sehingga ketika suatu gambar memiliki banyak bagian yang cerah maka gambar
tersebut banyak memiliki elemen berwarna putih, sebaliknya gambar yang condong berwarna
gelap memiliki banyak elemen berwarna hitam.
4. Histogram Gray Scale Image dari Livecam
#include <opencv2opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
VideoCapture cap(0);
if (cap.isOpened() == false)
{
cout << "Cannot open the video file" << endl;
cin.get();
return -1;
}
while (1)
{
Mat frame, gray_frame;
cap >> frame;
cap.read(frame);
cvtColor(frame, gray_frame, COLOR_BGR2GRAY);
char c = (char)waitKey(1);
if (c == 27)
break;
/// Establish the number of bins
int histSize = 256;
/// Set the ranges
float range[] = { 0, 256 };
const float* histRange = { range };
bool uniform = true; bool accumulate = false;
Mat b_hist;
/// Compute the histograms:
calcHist(&gray_frame, 1, 0, Mat(), b_hist, 1, &histSize, &histRange,
uniform, accumulate);
// Draw the histograms
int hist_w = 512; int hist_h = 400;
int bin_w = cvRound((double)hist_w / histSize);
Mat histImage(hist_h, hist_w, CV_8UC3, Scalar(0, 0, 0));
/// Normalize the result to [ 0, histImage.rows ]
normalize(b_hist, b_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());
/// Draw Histogram
for (int i = 1; i < histSize; i++)
{
line(histImage, Point(bin_w*(i - 1), hist_h -
cvRound(b_hist.at<float>(i - 1))),
Point(bin_w*(i), hist_h -
cvRound(b_hist.at<float>(i))),
Scalar(255, 0, 0), 2, 8, 0);
}
/// Display
namedWindow("calcHist Demo", CV_WINDOW_AUTOSIZE);
imshow("calcHist Demo", histImage);
imshow("CAMERA", frame);
}
waitKey();
return EXIT_SUCCESS;
}
5. Analisa
Ketika kamera menangkap suatu gambar yang memiliki intensitas yang rendah (0,0,0) maka grafik
akan mengalami kenaikan dari sisi kiri dan semakin terang gambar tersebut maka angka kenaikan
grafik akan semakin ke kanan. Berdasarkan hasil percobaan ini, dapat diketahui bahwa intensitas
cahaya pada gambar cenderung terang tetapi gambar juga menangkap objek yang berwarna gelap
sehingga grafik menunjukkan kenaikan di sisi kiri dan kenaikan grafik yang signifikan berada di
sebelah kanan karena gambar memiliki banyak bagian yang cenderung terang sehingga data yang
terbaca oleh grafik mendekati kea rah intensitas yang tinggi sekitar 255.
Histogram RGB Image dari Livecam
#include <opencv2opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
VideoCapture cap(0);
if (cap.isOpened() == false)
{
cout << "Cannot open the video file" << endl;
cin.get();
return -1;
}
while (1)
{
Mat frame;
cap >> frame;
char c = (char)waitKey(1);
if (c == 27)
break;
/// Separate the image in 3 places ( B, G and R )
6. vector<Mat> bgr_planes;
split(frame, bgr_planes);
/// Establish the number of bins
int histSize = 256;
/// Set the ranges ( for B,G,R) )
float range[] = { 0, 256 };
const float* histRange = { range };
bool uniform = true; bool accumulate = false;
Mat b_hist, g_hist, r_hist;
/// Compute the histograms:
calcHist(&bgr_planes[0], 1, 0, Mat(), b_hist, 1, &histSize, &histRange,
uniform, accumulate);
calcHist(&bgr_planes[1], 1, 0, Mat(), g_hist, 1, &histSize, &histRange,
uniform, accumulate);
calcHist(&bgr_planes[2], 1, 0, Mat(), r_hist, 1, &histSize, &histRange,
uniform, accumulate);
// Draw the histograms for B, G and R
int hist_w = 512; int hist_h = 400;
int bin_w = cvRound((double)hist_w / histSize);
Mat histImage(hist_h, hist_w, CV_8UC3, Scalar(0, 0, 0));
/// Normalize the result to [ 0, histImage.rows ]
normalize(b_hist, b_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());
normalize(g_hist, g_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());
normalize(r_hist, r_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());
/// Draw for each channel
for (int i = 1; i < histSize; i++)
{
line(histImage, Point(bin_w*(i - 1), hist_h -
cvRound(b_hist.at<float>(i - 1))),
Point(bin_w*(i), hist_h -
cvRound(b_hist.at<float>(i))),
Scalar(255, 0, 0), 2, 8, 0);
line(histImage, Point(bin_w*(i - 1), hist_h -
cvRound(g_hist.at<float>(i - 1))),
Point(bin_w*(i), hist_h -
cvRound(g_hist.at<float>(i))),
Scalar(0, 255, 0), 2, 8, 0);
line(histImage, Point(bin_w*(i - 1), hist_h -
cvRound(r_hist.at<float>(i - 1))),
Point(bin_w*(i), hist_h -
cvRound(r_hist.at<float>(i))),
Scalar(0, 0, 255), 2, 8, 0);
}
/// Display
namedWindow("calcHist Demo", CV_WINDOW_AUTOSIZE);
imshow("calcHist Demo", histImage);
imshow("CAMERA", frame);
}
waitKey();
return EXIT_SUCCESS;
}
7. Analisa
Komposisi warna pada gambar tersebut menunjukkan jika grafik mengalami kenaikan pada
intensitas yang rendah (0,0,0) karena pada gambar yang terbaca oleh kamera menangkap objek
yang berwarna gelap, sehingga grafik RGB mengalami kenaikan yang cukup tinggi yang berarti
bahwa pada intensitas tersebut mengalami percampuran ketiga warna yang cukup tinggi untuk
menghasilkan objek berwarna gelap. Sama halnya dengan sisi lain dari gambar tersebut yang
memiliki intensitas yang tinggi yakni mendekati nilai 255 karena camera menangkap objek yang
berwarna terang dengan environment lighting yang cukup bagus sehingga grafik mulai mengalami
kenaikan pada nilai tengah yang berada di sekitar intensitas 128 yang berarti bahwa percampuran
warna dominan putih atau warna cerah cukup tinggi untuk menghasilkan sisi bagian yang berwarna
terang pada gambar. Sehingga, ketika kamera menangkap objek kertas yang berwarna putih, grafik
akan mengalami kenaikan yang tinggi pada intensitas nilai 255 sedangkan pada intensitas yang
rendah (0,0,0) mengalami kelandaian grafik.
Histogram RGB Image dari Image
#include <opencv2opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
Mat frame, gray_frame;
frame = imread("histo3.JPG", CV_LOAD_IMAGE_COLOR); // Read the file "image.jpg".
imshow("RGB Image", frame);
/// Separate the image in 3 places ( B, G and R )
vector<Mat> bgr_planes;
split(frame, bgr_planes);
/// Establish the number of bins
int histSize = 256;
/// Set the ranges
9. Image2
Image3
Analisa
Grafik pada image1 menunjukkan kenaikan yang tinggi pada sisi kiri karena gambar yang memiliki
warna gelap sehingga percampuran warna RGB pada intensitas rendah cukup tinggi untuk
menghasilkan warna gelap tersebut. Seperti halnya pada hasil pembacaan image2 yang memiliki
sisi gelap tetapi ada sedikit dari gambar yang memiliki warna terang sehingga yang tergambar di
grafik cukup merata yakni pada nilai intensitas 0 – 128, hal ini juga terlihat pada grafik hasil
pembacaan image3 dimana gambar tersebut memilik warna yang terang sehingga grafik
menunjukkan kenaikan pada intensitas 128 – 255 yang berarti bahwa perpaduan warna RGB
dengan intensitas 128 – 255 cukup tinggi untuk menghasilkan gambar yang berwarna terang
tersebut. Hal ini terbukti pada hasil pembacaan grafik biru yang mengalami kenaikan paling tinggi
pada intensitas 255 karena gambar memiliki warna terang yang menunjukkan objek langit dengan
warna biru.
Histogram Equalization
#include <opencv2opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
10. using namespace std;
using namespace cv;
using std::cout;
int main(int argc, char** argv)
{
//memulai capture video
VideoCapture cap(0);
if (!cap.isOpened())
return -1;
//mendapatkan nilai dimensi video, disimpan dalam variabel, ditampilkan
int frame_width = cap.get(CV_CAP_PROP_FRAME_WIDTH);
int frame_height = cap.get(CV_CAP_PROP_FRAME_HEIGHT);
printf("row %dn", frame_width);
printf("coloumn %dn", frame_height);
for (;;)
{
Mat frame; Mat hsv;
cap >> frame;
imshow("Frame", frame);
if (waitKey(30) >= 0)
break;
cap.read(frame);
cvtColor(frame, frame, COLOR_BGR2GRAY);
Mat dst;
equalizeHist(frame, dst);
imshow("Source image", frame);
imshow("Equalized Image", dst);
if (frame.empty())
{
cout << "ERROR blank framen";
break;
}
/// Establish the number of bins
int histSize = 256;
/// Set the ranges
float range[] = { 0, 256 };
const float* histRange = { range };
bool uniform = true; bool accumulate = false;
Mat hist;
/// Compute the histograms:
calcHist(&frame, 1, 0, Mat(), hist, 1, &histSize, &histRange, uniform,
accumulate
);
// Draw the histograms
int hist_w = 512; int hist_h = 400;
int bin_w = cvRound((double)hist_w / histSize);
Mat histImage(hist_h, hist_w, CV_8UC3, Scalar(0, 0, 0));
/// Normalize the result to [ 0, histImage.rows ]
normalize(hist, hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());
/// Draw for channel
for (int i = 1; i < histSize; i++)
{
line(histImage, Point(bin_w*(i - 1), hist_h - cvRound(hist.at<float>(i
- 1))),
Point(bin_w*(i), hist_h - cvRound(hist.at<float>(i))),
Scalar(255, 255, 255), 2, 8, 0);
}
/// Display
namedWindow("calcHist Demo", CV_WINDOW_AUTOSIZE);
11. imshow("calcHist Demo", histImage);
}
return 0;
}
Analisa
Pada gambar histogram equalization jarak graylevel memiliki rentang antaranilai warna satu dengan
lainnya terdapat jarak yang cukup lebar yaitu artinya semakinsering/ intensitas greylevel yang
muncul itu tinggi. Histogram Equalization bertujuan mengubah pemetaan greylevel agar
sebarannya lebih menyebar pada kisaran 0 - 255, sehingga setiap derajat keabuan memiliki jumlah
pixel yang relatif sama.
Histogram Equalization Greyscale Mode Livecamera
#include <opencv2opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc.hpp"
12. #include <iostream>
using namespace std;
using namespace cv;
using std::cout;
int sourceHist(Mat frame) {
/// Establish the number of bins
int histSize = 256;
/// Set the ranges
float range[] = { 0, 256 };
const float* histRange = { range };
bool uniform = true; bool accumulate = false;
Mat histsrc;
/// Compute the histograms:
calcHist(&frame, 1, 0, Mat(), histsrc, 1, &histSize, &histRange,
uniform, accumulate);
// Draw the histograms
int hist_w = 512; int hist_h = 400;
int bin_w = cvRound((double)hist_w / histSize);
Mat histSrc(hist_h, hist_w, CV_8UC3, Scalar(0, 0, 0));
/// Normalize the result to [ 0, histSrc.rows ]
normalize(histsrc, histsrc, 0, histSrc.rows, NORM_MINMAX, -1, Mat());
/// Draw Histogram
for (int i = 1; i < histSize; i++)
{
line(histSrc, Point(bin_w * (i - 1), hist_h -
cvRound(histsrc.at<float>(i - 1))),
Point(bin_w * (i), hist_h -
cvRound(histsrc.at<float>(i))),
Scalar(255, 255, 255), 2, 8, 0);
}
namedWindow("Source histogram", CV_WINDOW_AUTOSIZE);
imshow("Source histogram", histSrc);
return 0;
}
int main(int argc, char** argv)
{
//memulai capture video
VideoCapture cap(0);
if (!cap.isOpened())
return -1;
//mendapatkan nilai dimensi video, disimpan dalam variabel, ditampilkan
int frame_width = cap.get(CV_CAP_PROP_FRAME_WIDTH);
int frame_height = cap.get(CV_CAP_PROP_FRAME_HEIGHT);
printf("row %dn", frame_width);
printf("coloumn %dn", frame_height);
for (;;)
{
Mat frame; Mat hsv;
cap >> frame;
//imshow("Frame", frame); //gambar asli
if (waitKey(30) >= 0)
break;
cap.read(frame);
cvtColor(frame, frame, COLOR_BGR2GRAY);
Mat dst;
equalizeHist(frame, dst);
imshow("Source image", frame); //gray scale
13. imshow("Equalized Image", dst); //equalized
if (frame.empty())
{
cout << "ERROR blank framen";
break;
}
/// Establish the number of bins
int histSize = 256;
/// Set the ranges
float range[] = { 0, 256 };
const float* histRange = { range };
bool uniform = true; bool accumulate = false;
Mat hist; //srchist;
/// Compute the histograms:
calcHist(&dst, 1, 0, Mat(), hist, 1, &histSize, &histRange, uniform,
accumulate);
//calcHist(&frame, 1, 0, Mat(), srchist, 1, &histSize, &histRange, uniform,
accumulate);
// Draw the histograms
int hist_w = 512; int hist_h = 400;
int bin_w = cvRound((double)hist_w / histSize);
Mat histImage(hist_h, hist_w, CV_8UC3, Scalar(0, 0, 0));
//Mat histSrc(hist_h, hist_w, CV_8UC3, Scalar(0, 0, 0));
/// Normalize the result to [ 0, histImage.rows ]
normalize(hist, hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());
//normalize(srchist, srchist, 0, histSrc.rows, NORM_MINMAX, -1, Mat());
/// Draw for channel
for (int i = 1; i < histSize; i++)
{
line(histImage, Point(bin_w * (i - 1), hist_h -
cvRound(hist.at<float>(i - 1))),
Point(bin_w * (i), hist_h - cvRound(hist.at<float>(i))),
Scalar(255, 255, 255), 2, 8, 0);
}
/// Display
namedWindow("calcHist Demo", CV_WINDOW_AUTOSIZE);
imshow("calcHist Demo", histImage);
sourceHist(frame);
}
return 0;
}
14. Analisa
Histogram equalization merupakan metode perbaikan kualitas citra yang bertujuan untuk meratakan
persebaran nilai intensitas piksel suatu citra. Hal ini terlihat pada grafik dari gambar asli yang
belum mengalamu ekualisasi, persebaran nilai piksel nya masih terfokus pada rentang nilai 0 – 128
karena objek yang tertangkap kamera memiliki intensitas cahaya yang cukup serta adanya obje
yang berwarna gelap. Tetapi ketika sudah mengalami ekualifikasi pada gambar, data pembacaan
grafik menunjukkan persebarang nilai intensitas piksel yang merata dari rentang 0 – 255 yang
berarti bahwa gambar yang telah mengalami ekualifikasi mendapatkan perbaikan kualitas dari citra
image sehingga persebaran nilai intensitas piksel pada image tersebut lebih merata.
Histogram Equalization RGB dari Original livecam
#include <opencv2opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
using namespace std;
using namespace cv;
int RGB_grafik(Mat frame) {
Mat b_hist, g_hist, r_hist;
int histSize = 256;
/// Set the ranges
float range[] = { 0, 256 };
const float* histRange = { range };
bool uniform = true; bool accumulate = false;
/// Separate the image in 3 places ( B, G and R )
vector<Mat> bgr_planes;
split(frame, bgr_planes);
calcHist(&bgr_planes[0], 1, 0, Mat(), b_hist, 1, &histSize, &histRange, uniform,
accumulate);
calcHist(&bgr_planes[1], 1, 0, Mat(), g_hist, 1, &histSize, &histRange, uniform,
accumulate);
calcHist(&bgr_planes[2], 1, 0, Mat(), r_hist, 1, &histSize, &histRange, uniform,
accumulate);
15. // Draw the histograms for B, G and R
int hist_w = 512; int hist_h = 400;
int bin_w = cvRound((double)hist_w / histSize);
Mat histImage(hist_h, hist_w, CV_8UC3, Scalar(0, 0, 0));
/// Normalize the result to [ 0, histImage.rows ]
normalize(b_hist, b_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());
normalize(g_hist, g_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());
normalize(r_hist, r_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());
/// Draw for each channel
for (int i = 1; i < histSize; i++)
{
line(histImage, Point(bin_w*(i - 1), hist_h -
cvRound(b_hist.at<float>(i - 1))),
Point(bin_w*(i), hist_h -
cvRound(b_hist.at<float>(i))),
Scalar(255, 0, 0), 2, 8, 0);
line(histImage, Point(bin_w*(i - 1), hist_h -
cvRound(g_hist.at<float>(i - 1))),
Point(bin_w*(i), hist_h -
cvRound(g_hist.at<float>(i))),
Scalar(0, 255, 0), 2, 8, 0);
line(histImage, Point(bin_w*(i - 1), hist_h -
cvRound(r_hist.at<float>(i - 1))),
Point(bin_w*(i), hist_h -
cvRound(r_hist.at<float>(i))),
Scalar(0, 0, 255), 2, 8, 0);
}
namedWindow("RGB histogram", CV_WINDOW_AUTOSIZE);
imshow("RGB histogram", histImage);
return 0;
}
int main(int argc, char* argv[])
{
//int RGB_grafik(frame);
//Open the video file for reading
VideoCapture cap(0);
// if not success, exit the program
if (cap.isOpened() == false)
{
cout << "Cannot open the video file" << endl;
cin.get(); //wait for any key press
return -1;
}
/// Establish the number of bins
int histSize = 256;
/// Set the ranges
float range[] = { 0, 256 };
const float* histRange = { range };
bool uniform = true; bool accumulate = false;
Mat hist;
//Define the names of windows
String windowNameOfOriginalImage = "Original Video";
String windowNameOfHistogramEqualized = "Histogram Equalized Video";
// Create windows with the above names
namedWindow(windowNameOfOriginalImage, WINDOW_NORMAL);
namedWindow(windowNameOfHistogramEqualized, WINDOW_NORMAL);
while (true)
{
16. Mat frame;
bool bSuccess = cap.read(frame); // Read a new frame from the video file
//Breaking the while loop at the end of the video
if (bSuccess == false)
{
cout << "Found the end of the video" << endl;
break;
}
//Convert the frame from BGR to YCrCb color space
Mat hist_equalized_image;
cvtColor(frame, hist_equalized_image, COLOR_BGR2YCrCb);
//Split the image into 3 channels; Y, Cr and Cb channels respectively and
store it in a std::vector
vector<Mat> vec_channels;
split(hist_equalized_image, vec_channels);
//Equalize the histogram of the Y channel
equalizeHist(vec_channels[0], vec_channels[0]);
//Merge 3 channels in the std::vector to form the color image in YCrCB color
space.
merge(vec_channels, hist_equalized_image);
//Convert the histogram equalized image from YCrCb to BGR color space again
cvtColor(hist_equalized_image, hist_equalized_image, COLOR_YCrCb2BGR);
Mat b_hist, g_hist, r_hist;
calcHist(&vec_channels[0], 1, 0, Mat(), b_hist, 1, &histSize, &histRange,
uniform, accumulate);
calcHist(&vec_channels[1], 1, 0, Mat(), g_hist, 1, &histSize, &histRange,
uniform, accumulate);
calcHist(&vec_channels[2], 1, 0, Mat(), r_hist, 1, &histSize, &histRange,
uniform, accumulate);
// Draw the histograms
int hist_w = 512; int hist_h = 400;
int bin_w = cvRound((double)hist_w / histSize);
Mat histImage(hist_h, hist_w, CV_8UC3, Scalar(0, 0, 0));
/// Normalize the result to [ 0, histImage.rows ]
normalize(hist, hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());
normalize(g_hist, g_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());
normalize(r_hist, r_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());
for (int i = 1; i < histSize; i++)
{
line(histImage, Point(bin_w*(i - 1), hist_h -
cvRound(b_hist.at<float>(i - 1))),
Point(bin_w*(i), hist_h -
cvRound(b_hist.at<float>(i))),
Scalar(255, 0, 0), 2, 8, 0);
line(histImage, Point(bin_w*(i - 1), hist_h -
cvRound(g_hist.at<float>(i - 1))),
Point(bin_w*(i), hist_h -
cvRound(g_hist.at<float>(i))),
Scalar(0, 255, 0), 2, 8, 0);
line(histImage, Point(bin_w*(i - 1), hist_h -
cvRound(r_hist.at<float>(i - 1))),
Point(bin_w*(i), hist_h -
cvRound(r_hist.at<float>(i))),
Scalar(0, 0, 255), 2, 8, 0);
}
17. //show frames in the created windows
imshow(windowNameOfOriginalImage, frame);
imshow(windowNameOfHistogramEqualized, hist_equalized_image);
imshow("calcHist Demo", histImage);
RGB_grafik(frame);
if (waitKey(5) == 27)
{
cout << "Esc key is pressed by the user. Stopping the video" << endl;
break;
}
}
destroyAllWindows(); //Destroy all opened windows
return 0;
}
Analisa
Melihat tujuan dari histogram equalization yang merupakan metode perbaikan kualitas citra untuk
meratakan persebaran nilai intensitas piksel suatu citra. Hal ini terlihat pada grafik dari gambar asli
dari livecam yang belum mengalami ekualisasi, persebaran nilai piksel RGB nya masih terfokus
pada rentang nilai 0 – 128 karena objek yang tertangkap kamera memiliki intensitas cahaya yang
cukup serta adanya objek yang berwarna gelap sehingga perpaduan warna RGB nya juga berada
pada rentang nilai 0 – 128. Tetapi ketika sudah mengalami ekualifikasi pada gambar, data
pembacaan grafik menunjukkan persebarang nilai intensitas piksel yang merata dari rentang 0 – 255
yang berarti bahwa gambar yang telah mengalami ekualifikasi mendapatkan perbaikan kualitas dari
citra image sehingga persebaran nilai intensitas piksel pada image tersebut lebih merata. Terutama
pada warna biru yang memiliki persebaran merata dari rentang nilai 0 – 255 dibandingkan
persebaran warna merah dan hijau yang masih berada pada rentang nilai 128.
18. SEGMENTASI
1. Histogram RGB Image dari Image File
#include <opencv2opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
Mat frame, gray_frame;
frame = imread("book2.JPG", CV_LOAD_IMAGE_COLOR); // Read the file "image.jpg".
//imshow("RGB Image", frame);
/// Separate the image in 3 places ( B, G and R )
vector<Mat> bgr_planes;
split(frame, bgr_planes);
/// Establish the number of bins
int histSize = 256;
/// Set the ranges
float range[] = { 0, 256 };
const float* histRange = { range };
bool uniform = true; bool accumulate = false;
Mat b_hist, g_hist, r_hist;
/// Compute the histograms:
calcHist(&bgr_planes[0], 1, 0, Mat(), b_hist, 1, &histSize, &histRange,
uniform, accumulate);
calcHist(&bgr_planes[1], 1, 0, Mat(), g_hist, 1, &histSize, &histRange,
uniform, accumulate);
calcHist(&bgr_planes[2], 1, 0, Mat(), r_hist, 1, &histSize, &histRange,
uniform, accumulate);
// Draw the histograms for B, G and R
int hist_w = 512; int hist_h = 400;
int bin_w = cvRound((double)hist_w / histSize);
Mat histImage(hist_h, hist_w, CV_8UC3, Scalar(0, 0, 0));
/// Normalize the result to [ 0, histImage.rows ]
normalize(b_hist, b_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());
normalize(g_hist, g_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());
normalize(r_hist, r_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());
/// Draw Histogram
for (int i = 1; i < histSize; i++)
{
line(histImage, Point(bin_w*(i - 1), hist_h -
cvRound(b_hist.at<float>(i - 1))),
Point(bin_w*(i), hist_h -
cvRound(b_hist.at<float>(i))),
Scalar(255, 0, 0), 2, 8, 0);
line(histImage, Point(bin_w*(i - 1), hist_h -
cvRound(g_hist.at<float>(i - 1))),
Point(bin_w*(i), hist_h -
19. cvRound(g_hist.at<float>(i))),
Scalar(0, 255, 0), 2, 8, 0);
line(histImage, Point(bin_w*(i - 1), hist_h -
cvRound(r_hist.at<float>(i - 1))),
Point(bin_w*(i), hist_h -
cvRound(r_hist.at<float>(i))),
Scalar(0, 0, 255), 2, 8, 0);
}
/// Display
imshow("RGB Histogram Image", histImage);
imshow("Original Image", frame);
waitKey();
return EXIT_SUCCESS;
}
2. Hasil gambar intensitas R > 125
#include <opencv2opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
Mat frame, gray_frame;
frame = imread("book2.JPG", CV_LOAD_IMAGE_COLOR); // Read the file "image.jpg".
/// Separate the image in 3 places ( B, G and R )
vector<Mat> bgr_planes;
split(frame, bgr_planes);
/// Establish the number of bins
int histSize = 256;
/// Set the ranges
float range[] = { 125, 256 };
const float* histRange = { range };
bool uniform = true; bool accumulate = false;
20. Mat b_hist, g_hist, r_hist;
/// Compute the histograms:
calcHist(&bgr_planes[2], 1, 0, Mat(), r_hist, 1, &histSize, &histRange,
uniform, accumulate);
// Draw the histograms for B, G and R
int hist_w = 512; int hist_h = 400;
int bin_w = cvRound((double)hist_w / histSize);
Mat histImage(hist_h, hist_w, CV_8UC3, Scalar(0, 0, 0));
/// Normalize the result to [ 0, histImage.rows ]
normalize(r_hist, r_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());
/// Draw Histogram
for (int i = 1; i < histSize; i++)
{
line(histImage, Point(bin_w*(i - 1), hist_h -
cvRound(r_hist.at<float>(i - 1))),
Point(bin_w*(i), hist_h -
cvRound(r_hist.at<float>(i))),
Scalar(0, 0, 255), 2, 8, 0);
}
/// Display
imshow("RGB Histogram Image", histImage);
imshow("Original Image", frame);
waitKey();
return EXIT_SUCCESS;
}
Analisa
Segmentasi merupakan proses pemisahan latar depan – latar belakang suatu image. Untuk case
pada soal ini dimana kami diminta untuk menampilkan grafik dari warna merah yang memiliki nilai
intensitas R lebih dari 125, sehingga pada variabel array yang digunakan untuk menampung nilai
dari warna diubah dengan nilai pada rentang 126 – 255 yang pada grafik menghasilkan klaster
warna merah yang memiliki intensitas pada rentang 126 – 255 dengan kerapatan yang cukup stabil.
Hal ini dikarenakan pada pemetaan warna citra dari image masukan dikelompokkan sesuai dengan
kesamaan warna yang dimiliki oleh objek pada gambar. Setiap piksel citra dikonversi dalam suatu
garis vector RGB untuk selanjutnya ditampilkan berdasarkan rata – rata dari kelompok warna yang
dihasilkan.
21. Menampilkan Warna Merah Saja dari Image
#include <opencv2opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
Mat frame;
frame = imread("book2.JPG", CV_LOAD_IMAGE_COLOR);
/// Separate the image in 3 places ( B, G and R )
vector<Mat> bgr_planes;
split(frame, bgr_planes);
/*
Mat redOnly, mask;
Mat hsv_image;
cvtColor(frame, hsv_image, COLOR_BGR2HSV);
inRange(hsv_image, Scalar(0, 120, 70), Scalar(10, 255, 255), mask);
*/
Mat g, output;
g = Mat::zeros(Size(frame.cols, frame.rows), CV_8UC1);
// Showing Red Channel
// G and B channels are kept as zero matrix for visual perception
vector<Mat> channels;
channels.push_back(g);
channels.push_back(g);
channels.push_back(bgr_planes[2] > 125);
/// Merge the three channels
merge(channels, output);
namedWindow("Red", 1);
///Converting image from BGR to HSV color space.
Mat hsv_image;
cvtColor(frame, hsv_image, COLOR_BGR2HSV);
/// Creating masks to detect the upper and lower red color.
Mat mask1, mask2, red_output;
inRange(hsv_image, Scalar(0, 40, 30), Scalar(10, 255, 255), mask1);
//inRange(hsv_image, Scalar(130, 120, 120), Scalar(180, 255, 255), mask2);
// Generating the final mask
//mask1 = mask1 + mask2;
bitwise_and(frame, frame, red_output, mask1);
/// Establish the number of bins
int histSize = 256;
/// Set the ranges ( for B,G,R) )
float range[] = { 0, 256 };
const float* histRange = { range };
bool uniform = true; bool accumulate = false;
23. Segmentasi pada suatu citra ( image segmentation) merupakan langkah awal pada proses analisa
citra yang bertujuan untuk mengambil informasi yang terdapat di dalam suatu citra. Segmentasi
citra membagi suatu citra ke dalam bagian-bagian atau objek-objek tertentu. Sampai sejauh
mana pembagian tersebut dilakukan tergantung pada masalah yang dihadapi. Idealnya, langkah
segmentasi tersebut dihentikan pada saat objek yang diinginkan sudah berhasil dipisahkan. Pada
kasus diatas, dari sampul buku terlebih dahulu dipisahkan dengan trasholding untuk mengetahui
dan memisahkan warna merah. Setelah warna merah sudah dapat diketahui selanjutnya bagian yang
selain warna merah dihitankan atau dihapus.