基于qml创建最简单的图像处理程序(2)-使用c++&qml进行图像处理
基于qml创建最简单的图像处理程序(1)-基于qml创建界面
http://www.cnblogs.com/jsxyhelu/p/8343310.html
课程1附件
https://files.cnblogs.com/files/jsxyhelu/%E9%98%B6%E6%AE%B5%E4%BB%A3%E7%A0%811.zip
基于qml创建最简单的图像处理程序(2)-使用c++&qml进行图像处理
http://www.cnblogs.com/jsxyhelu/p/8361441.html
课程2附件
https://files.cnblogs.com/files/jsxyhelu/%E9%98%B6%E6%AE%B5%E4%BB%A3%E7%A0%812.zip
基于qml创建最简单的图像处理程序(3)-使用opencv&qml进行图像处理
http://www.cnblogs.com/jsxyhelu/p/8361443.html
课程3附件
https://files.cnblogs.com/files/jsxyhelu/%E9%98%B6%E6%AE%B5%E4%BB%A3%E7%A0%813.zip
Button {
text : "灰度";
style : btnStyle;
onPressedChanged : {
busy.running = true;
// processor.process(fileDialog.fileUrl, ImageProcessor.Gray);
}
}
//浮雕效果
Button {
text : "浮雕";
style : btnStyle;
onPressedChanged : {
busy.running = true;
// processor.process(fileDialog.fileUrl, ImageProcessor.Emboss);
}
}
//黑白效果
Button {
text : "黑白";
style : btnStyle;
onPressedChanged : {
busy.running = true;
// processor.process(fileDialog.fileUrl, ImageProcessor.Binarize);
}
}
ImageProcessor {
id : processor;
onFinished : {
imageViewer.source = "file:///" +newFile;
}
}
qmlRegisterType <ImageProcessor >( "GO.ImageProcessor", 1, 0, "ImageProcessor");
{
QFileInfo fi(sourceFile);
QString destFile = QString( "%1/%2_%3").arg(m_tempPath).arg(( int)algorithm).arg(fi.fileName());
AlgorithmRunnable *r = new AlgorithmRunnable(sourceFile,destFile,algorithm, this);
m_runnables.append(r);
r - >setAutoDelete( false);
QThreadPool : :globalInstance() - >start(r);
}
static void _gray(QString sourceFile, QString destFile)
{
QImage image(sourceFile);
if(image.isNull())
{
qDebug() << "load " << sourceFile << " failed! ";
return;
}
qDebug() << "depth - " << image.depth();
int width = image.width();
int height = image.height();
QRgb color;
int gray;
for( int i = 0; i < width; i ++)
{
for( int j = 0; j < height; j ++)
{
color = image.pixel(i, j);
gray = qGray(color);
image.setPixel(i, j, qRgba(gray, gray, gray, qAlpha(color)));
}
}
image.save(destFile);
}
static void _binarize(QString sourceFile, QString destFile)
{
QImage image(sourceFile);
if(image.isNull())
{
qDebug() << "load " << sourceFile << " failed! ";
return;
}
int width = image.width();
int height = image.height();
QRgb color;
QRgb avg;
QRgb black = qRgb( 0, 0, 0);
QRgb white = qRgb( 255, 255, 255);
for( int i = 0; i < width; i ++)
{
for( int j = 0; j < height; j ++)
{
color = image.pixel(i, j);
avg = (qRed(color) + qGreen(color) + qBlue(color)) / 3;
image.setPixel(i, j, avg > = 128 ? white : black);
}
}
image.save(destFile);
}
static void _emboss(QString sourceFile, QString destFile)
{
QImage image(sourceFile);
if(image.isNull())
{
qDebug() << "load " << sourceFile << " failed! ";
return;
}
int width = image.width();
int height = image.height();
QRgb color;
QRgb preColor = 0;
QRgb newColor;
int gray, r, g, b, a;
for( int i = 0; i < width; i ++)
{
for( int j = 0; j < height; j ++)
{
color = image.pixel(i, j);
r = qRed(color) - qRed(preColor) + 128;
g = qGreen(color) - qGreen(preColor) + 128;
b = qBlue(color) - qBlue(preColor) + 128;
a = qAlpha(color);
gray = qGray(r, g, b);
newColor = qRgba(gray, gray, gray, a);
image.setPixel(i, j, newColor);
preColor = newColor;
}
}
image.save(destFile);
}
//END 具体的图像处理算法,注意图片处理的结果直接保存到了destFile中去//
附件列表
目前方向:图像拼接融合、图像识别 联系方式:jsxyhelu@foxmail.com