i try this little bit a of code :
try {
InitializeMagick(*argv);
//create a base image
Image image("400x100",font_color);
//construct a drawing list
std::list<Magick::Drawable> drawList;
//add tracing elements
drawList.push_back(DrawableRectangle(0,0,400,100)); // Draw a rectangle ( the sign)
drawList.push_back(DrawableStrokeColor("black")); // Outline Color
drawList.push_back(DrawableFillColor(font_color)); // Fill color
drawList.push_back(DrawableStrokeWidth(5));
drawList.push_back(DrawablePointSize(50));
drawList.push_back(DrawableFont("#Arial"));
drawList.push_back(DrawableStrokeColor(police_color));
drawList.push_back(DrawableText(10,70,ville));
drawList.push_back(DrawableText(300,70,distance));
image.draw(drawList);
image.write(filedest);
}
catch(exception & error_)
{
cout<<"Caught exception : " << error_.what() << endl;
}
but i get this error when i start the program :
proto.exe:unable to read font `#Arial' # error/annotate.c/RenderFreetype/1126
Just drop the # sign in the font name. It's not needed for the Magick::DrawableFont method.
drawList.push_back(DrawableFont("Arial"));
You can verify the fonts available by running the identify utility.
identify -list font | more
Related
I'm making my own text editor with C++ and the SFML multi-media library. I'm now trying to implement a user interface so users can interact and select documents to edit. I have this function:
std::vector<sf::Text> Menu::GetAllTextOptions(TextHandler& handler, sf::Font font) {
std::vector<TextDocument>* all_available_documents = handler.GetTextDocuments();
std::vector<sf::Text> menu_text_options;
for (int i = 0; i < all_available_documents->size(); i++) {
sf::Text text;
text.setFont(font);
text.setString(std::to_string(i) + ") " + all_available_documents->at(i).GetDocumentName() + '\n');
menu_text_options.push_back(text);
}
return menu_text_options;
}
What this is supposed to do is collect all of the names of already existing text documents in a path that I have specified (the code behind gathering the TextDocument objects works perfectly). It then makes a text object, sets a font to it and sets the string to the name of the document. When I std::cout the count of the vector, it displays correctly the amount of documents that exist.
I then have a function that is supposed to go through the vector of texts and draw all of them, so they can be later displayed:
// ACCESS VIOLATION ERROR
void Menu::DrawAllOptions(sf::RenderWindow& window, std::vector<sf::Text>&
menu_text_options) {
std::cout << menu_text_options.size() << " is the current size " << std::endl;
try {
for (int i = 0; i < menu_text_options.size(); i++) {
// EXCEPTION THROWN HERE
window.draw(menu_text_options.at(i));
}
}
catch (const std::exception& ex) {
std::cout << "Exception: " << ex.what() << '\n';
}
}
Finally, I have the main loop where everything comes into place:
std::string Menu::MenuControl(TextHandler& handler) {
Utility utility;
sf::RenderWindow menu_window(sf::VideoMode(800, 600), "Menu");
sf::Color backgroundColor(0, 32, 63);
sf::Event event;
sf::Font font;
sf::Text menu_text;
utility.CheckFontLoaded(font, "../8bitfont.ttf");
std::vector<sf::Text> menu_text_options = GetAllTextOptions(handler, font);
int menu_counter = 0; // Start at the first document, count goes up and down
with arrows
menu_text.setOrigin(sf::Vector2f(-20.f, 0.f));
menu_text.setFont(font);
while (menu_window.isOpen()) {
// DRAWING
menu_window.clear(backgroundColor); // Setting menu background color
//window.draw(background_overlay);
DrawAllOptions(menu_window, menu_text_options);
// DISPLAYING
menu_window.display();
// TO DO - ABSTRACT USER INPUT LOGIC
while (menu_window.pollEvent(event)) {
switch (event.type)
{
case sf::Event::Closed:
menu_window.close();
return "Test";
break;
case sf::Event::TextEntered:
if (event.text.unicode < 128) {
}
break;
case sf::Event::KeyReleased:
break;
}
}
}
return "Not correctly working";
}
The exact error I get is:
Exception thrown at 0x00007FFA3E2869E9 (sfml-graphics-d-2.dll) in texteditor.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.
At this point, I've attempted putting a try catch block, initializing the vector with new and making everything within the main loop function. I am sensing its something to do with the Text objects that I push into the vector, but I tried initializing them differently as well with no success. Any suggestions would be greatly appreciated!
The answer to the problem, as mentioned by #Botje, is that the function Menu::GetAllTextOptions was getting a copy of font, which ultimately ended up not being loaded and resulting in an access violation.
I want to make an annotation in a gif image using ImageMagick and specifically Magick++, the code is quite simple, but the output image has artifacts in the text, if the gif does not move, then the artifacts do not appear, here:
here is the code itself, very simple:
int main()
{
InitializeMagick(nullptr);
list<Image> *imageList = new list<Image>();
try {
readImages(imageList, "source.gif" );
}
catch( exception &error_ )
{
cout << "Caught exception: " << error_.what() << endl;
return 1;
}
for(Image &i : *imageList) {
i.fontPointsize(36);
i.font("helvetica-bold");
i.fillColor(Color("white"));
i.fontStyle(MagickCore::ObliqueStyle);
i.annotate("why are you lagging", SouthGravity);
}
writeImages(imageList->begin(), imageList->end(), "/home/deymos/GifnText/n.gif");
return 0;
I tried to save the list of images as png and this is what I saw when the movement on the gif started:
is it possible to fix it, or is it a bug?
If this cannot be fixed, maybe there are similar tools with which I can implement text on gifs? or at least a library that can disassemble gifs into images and fold, I can do the rest with qt, tnx.
I am new to C++ gui design and I am not too familiar with using pointers. Recently I have run into a few problems when trying to get an OpenCV Mat Image to display in a PictureBox in a constructed gui. I have searching online and even found a very similar post to my question but when trying to implement the guidance I ran into an exception when trying to operate the gui.
A very similar post
Displaying webcam feed in cv::Mat format in a picturebox
Code I grabbed from this post to save you a click:
void DrawCVImage(System::Windows::Forms::Control^ control, cv::Mat& colorImage)
{
System::Drawing::Graphics^ graphics = control->CreateGraphics();
System::IntPtr ptr(colorImage.ptr());
System::Drawing::Bitmap^ b = gcnew System::Drawing::Bitmap(colorImage.cols,colorImage.rows,colorImage.step,System::Drawing::Imaging::PixelFormat::Format24bppRgb,ptr);
System::Drawing::RectangleF rect(0,0,control->Width,control->Height);
graphics->DrawImage(b,rect);
delete graphics;
}
Now I am trying to display a "video" feed (really an array of cv::Mat Objects) but I am having a
"Source Not Available"/System.ArgumentException: 'Parameter is not valid.'
screen come up when I attempt to call the function that houses that playback. I also know specific line of code that throws the issue is the line
System::Drawing::Bitmap^ b = gcnew System::Drawing::Bitmap(colorImage.cols,colorImage.rows,colorImage.step,System::Drawing::Imaging::PixelFormat::Format24bppRgb,ptr);
Now for specifics, the form has an event (currently the click on the picture box, but I want to move to a "play" button in the future) and on this event, the code:
private: System::Void leftEyeImage_Click(System::Object^ sender, System::EventArgs^ e) {
std::cout << "Click Received" << std::endl;
cv::Mat& frame = cv::imread("Desktop/testcapture.png");
std::cout << "Import successful" << std::endl;
drawLeftEye(this, frame);
}
This code does get execute on click and starts the function drawLeftEye. The function is a modified version of the code from the other post and is below:
This is on the ShowResults.cpp file
namespace DevProject {
void ShowResults::drawLeftEye(System::Windows::Forms::Control^ control, cv::Mat& framebmp) {
System::Drawing::Graphics^ graphics = control->CreateGraphics();
std::cout << "Now Here" << std::endl;
System::IntPtr ptr(framebmp.data);
// Issue line
System::Drawing::Bitmap^ b = gcnew System::Drawing::Bitmap(framebmp.cols, framebmp.rows, framebmp.step, System::Drawing::Imaging::PixelFormat::Format32bppRgb, ptr);
std::cout << "Converted successfully" << std::endl;
System::Drawing::RectangleF rect(0, 0, control->Width, control->Height); //No issue
graphics->DrawImage(b, rect);
std::cout << "Now Here before delete" << std::endl;
delete graphics;
//delete b;
}
}
I know based on my cout statements that I do make it into my function and I know my code compiles and runs through the function if I comment out the line:
System::Drawing::Bitmap^ b = gcnew System::Drawing::Bitmap(framebmp.cols, framebmp.rows, framebmp.step, System::Drawing::Imaging::PixelFormat::Format32bppRgb, ptr);
//As well as (but only because b is defined in the line above^
graphics->DrawImage(b, rect);
I am not quite sure how to fix this, my friend mentioned this could be a memory issue but I don't know how I would go about fixing it. It is also very possible I have made a simple mistake in the design of this or where my pointers are going and I am just not competent enough to know the error.
By the way the pointer for "this" that is called in the function is linked to the Windows Autogenerated code (from gui construction) of:
this->leftEyeImage->Anchor = System::Windows::Forms::AnchorStyles::None;
this->leftEyeImage->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
this->leftEyeImage->Location = System::Drawing::Point(11, 836);
this->leftEyeImage->Name = L"leftEyeImage";
this->leftEyeImage->Size = System::Drawing::Size(991, 646);
this->leftEyeImage->TabIndex = 4;
this->leftEyeImage->TabStop = false;
this->leftEyeImage->Click += gcnew System::EventHandler(this, &ShowResults::leftEyeImage_Click);
Any and all advice or tests would be very appreciated as I am both interested in the answer and the reasoning. Thanks in advance!
I'm creating an application using qt creator which read .off files as CGAL::Linear_cell_complex_for_combinatorial_map and preview it I want to make operations on the read mesh such as removing edge and restore it .
it shows the following error :
terminate called after throwing an instance of 'CGAL::Assertion_exception'
what(): CGAL ERROR: assertion violation!
Expr: is_insertable_cell_1_in_cell_2(adart1, adart2)
I searched about it but I cannot get an useful solution
QWidget* viewer ;
std::string filename;
Dart_handle dh3;
LCC_3 lcc;
QMainWindow qWin;
CGAL::DefaultColorFunctorLCC fcolor;
void MainWindow ::insertCell()
{
dh3=lcc.insert_cell_1_in_cell_2(lcc.darts().begin(), lcc.darts().end());
CGAL_assertion( lcc.is_valid() );
lcc.display_characteristics(std::cout) << ", valid=" <<
lcc.is_valid() << std::endl;
setCentralWidget( new CGAL::SimpleLCCViewerQt<LCC_3, CGAL::DefaultColorFunctorLCC>(&qWin ,
lcc,
"Basic LCC Viewer",
false,
fcolor ) );
show();
}
void MainWindow ::removeCell()
{
CGAL_assertion( (lcc.is_removable<2>(dh3)) );
lcc.remove_cell<1>(dh3);
CGAL_assertion( lcc.is_valid() );
lcc.display_characteristics(std::cout) << ", valid="
<< lcc.is_valid() << std::endl;
}
any help? or usefull links to simplify mesh or removing vertices , edges or faces ?
I appreciate any help
To insert an edge in a face, cf the doc here. For a face in a volume, the doc is there. You can also have a look at the example here.
The important thing to understand is when you add an edge into a face, you need to say where to insert the edge. This is the reason why you give two precise darts. This is similar when you want to insert a face into a volume: you need to give a sequence of darts which is a cycle of edges in the volume.
I would like to get the resolution of the selected camera and also get the raw frame in the videocapture but I have not found clearly at all how to do it. Could you help me!? Thanks in advance.
// Open camera for reading
cameraQt = new QCamera(cameras.at(cameraIdSelected));
if(!cameraQt->isAvailable())
ui->statusBar->showMessage(tr("Impossible to open camera...."));
cameraQt->setViewfinder(ui->centralWidget);
like : cameraQt->getResolution ?
Thanks.
I think you 1) Should load the cam 2) get imageCapture (raw) from the loaded cam. There is no direct simple type of a resolution, because camera will have a list of supported resolutions, you can set your device to one of those.
Try this to get the list of resolutions for a device:
QList<QByteArray> cameraDevices = QCamera::availableDevices();
QByteArray cameraDevice = cameraDevices[0];
QCamera *camera = new QCamera(cameraDevice);
camera->load();
qDebug() << "Camera status: " << camera->status();
QCameraImageCapture *imageCapture = new QCameraImageCapture(camera);
QList<QSize> resolutions = imageCapture->supportedResolutions();
QListIterator<QSize> it(resolutions);
while (it.hasNext()) {
qDebug() << "Resoution: " << it.next();
}