MCPcopy Create free account
hub / github.com/antmachineintelligence/mtgbmcode / main

Function main

compute/example/qimage_blur.cpp:92–145  ·  view source on GitHub ↗

this example shows how to load an image using Qt, apply a simple box blur filter, and then display it in a Qt window.

Source from the content-addressed store, hash-verified

90// this example shows how to load an image using Qt, apply a simple
91// box blur filter, and then display it in a Qt window.
92int main(int argc, char *argv[])
93{
94 QApplication app(argc, argv);
95
96 // check command line
97 if(argc < 2){
98 std::cout << "usage: qimage_blur [FILENAME]" << std::endl;
99 return -1;
100 }
101
102 // load image using Qt
103 QString fileName = argv[1];
104 QImage qimage(fileName);
105
106 size_t height = qimage.height();
107 size_t width = qimage.width();
108 size_t bytes_per_line = qimage.bytesPerLine();
109
110 qDebug() << "height:" << height
111 << "width:" << width
112 << "bytes per line:" << bytes_per_line
113 << "depth:" << qimage.depth()
114 << "format:" << qimage.format();
115
116 // create compute context
117 compute::device gpu = compute::system::default_device();
118 compute::context context(gpu);
119 compute::command_queue queue(context, gpu);
120 std::cout << "device: " << gpu.name() << std::endl;
121
122 // get the opencl image format for the qimage
123 compute::image_format format =
124 compute::qt_qimage_format_to_image_format(qimage.format());
125
126 // create input and output images on the gpu
127 compute::image2d input_image(context, width, height, format);
128 compute::image2d output_image(context, width, height, format);
129
130 // copy host qimage to gpu image
131 compute::qt_copy_qimage_to_image2d(qimage, input_image, queue);
132
133 // apply box filter
134 box_filter_image(input_image, output_image, 7, 7, queue);
135
136 // copy gpu blurred image from to host qimage
137 compute::qt_copy_image2d_to_qimage(output_image, qimage, queue);
138
139 // show image as a pixmap
140 QLabel label;
141 label.setPixmap(QPixmap::fromImage(qimage));
142 label.show();
143
144 return app.exec();
145}

Callers

nothing calls this directly

Calls 10

box_filter_imageFunction · 0.85
heightMethod · 0.80
widthMethod · 0.80
depthMethod · 0.80
formatMethod · 0.80
nameMethod · 0.45
execMethod · 0.45

Tested by

no test coverage detected