does anyone know how to write a code(C/C++) to put text into images without using the puttext function in opencv? I'd been google-ing for this function for quite awhile, but didn't manage to get a solution.
Asked
Active
Viewed 5,499 times
0
-
a lot of people know that. what is your actual question? I doubt that this answer is what you were looking for. please read [ask] and improve your post. so you don't want to use OpenCV? what about other libraries? – Piglet Mar 20 '18 at 16:49
-
1What's the objection to `puttext()` exactly? – Mark Setchell Mar 20 '18 at 22:23
-
Thanks for the reply.Sorry it's my first time to post question here. As i'm trying to do image processing onto FPGA, OpenCV function cannot be accelerated using FPGA and is causing illegal memory access, thus, I need to write a C/C++ function to put text onto the image. – Ong Sie Siong Mar 21 '18 at 01:56
-
@MarkSetchell It's slow. Try overlaying 50-100 lines on a video stream at 30fps with putText() and see for yourself. – erdem Mar 03 '22 at 15:59
1 Answers
5
I commend CImg to you - it is clean, modern C++ and very capable. It is very simple to integrate in a project because it is *"header only** - just one include file and no libraries to link against.
It can read and write NetPBM files (PGM, PPM etc) natively without any special linking and can read and write everything else either using libjpeg
, libtiff
, libpng
or ImageMagick.
It can also display images on X11 or on Windows via GDI, if you want it to.
#include <iostream>
#include <cstdlib>
#define cimg_display 0
#include "CImg.h"
using namespace cimg_library;
using namespace std;
int main() {
// Create 640x480 image
CImg<unsigned char> image(640,480,1,3);
// Fill with magenta
cimg_forXY(image,x,y) {
image(x,y,0,0)=255;
image(x,y,0,1)=0;
image(x,y,0,2)=255;
}
// Make some colours
unsigned char cyan[] = {0, 255, 255 };
unsigned char black[] = {0, 0, 0 };
unsigned char yellow[] = {255, 255, 0 };
// Draw black text on cyan
image.draw_text(30,60,"Black 64pt on cyan",black,cyan,1,64);
// Draw yellow partially transparent text on black
image.draw_text(80,200,"Yellow 32pt on black semi-transparent",yellow,black,0.5,32);
// Save result image as NetPBM PNM - no libraries required
image.save_pnm("result.pnm");
}

Mark Setchell
- 191,897
- 31
- 273
- 432
-
Sorry for the late reply. Is this CImg header available in the SDSoC? I tried to include CImg.h in SDSoC but it doesn't seems to exist. – Ong Sie Siong Mar 26 '18 at 12:03
-
What is SDSoC please? Grab the file `CImg.h` from the link in first line of my answer. – Mark Setchell Mar 26 '18 at 12:17