Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
OpenCvExample1 is a OpenCV example how to display an image
and how to convert one to greyscale.
Technical facts
Application type(s)
Operating system(s) or programming environment(s)
IDE(s):
Project type:
C++ standard:
Compiler(s):
Libraries used:
OpenCV: version 2.3.1
Qt: version 4.8.1 (32 bit)
STL: GNU ISO C++ Library, version 4.6.3
#-------------------------------------------------
#
# Project created by QtCreator 2012-07-11T13:49:58
#
#-------------------------------------------------
QT += core
QT -= gui
unix {
CONFIG += link_pkgconfig
PKGCONFIG += opencv
}
#LIBS += -lopencv
TARGET = CppOpenCvExample1
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
RESOURCES += \
CppOpenCvExample1.qrc
|
main.cpp
#include <QFile>
#include <QResource>
#include <opencv2/opencv.hpp>
int main()
{
const std::string filename = "image.jpg";
//Create the source image if it does not exist
{
if (!QFile::exists(filename.c_str()))
{
QFile f((std::string(":/images/") + filename).c_str());
f.copy(filename.c_str());
}
assert(QFile::exists(filename.c_str()));
}
//Load the image
const cv::Mat image_original = cv::imread(filename);
assert(image_original.data);
//Create the resulting image
cv::Mat image_result;
cv::cvtColor(image_original,image_result,CV_RGB2GRAY );
cv::imwrite("R_grey.png", image_result );
//Display the original
cv::imshow("Original",image_original );
//Display the result
cv::imshow("Result", image_result );
//Wait for a key press
cv::waitKey(0);
}
|
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.

This page has been created by the tool CodeToHtml