Opening image with ImageMagick via c++ - c++

Creating a simple project for an open image with ImageMagick.
Using simple code:
#include "Magick++.h"
#include <iostream>
using namespace std;
using namespace Magick;
int main(int argc, char **argv)
{
const char *c = "test.png";
cout << c << endl;
try {
InitializeMagick(*argv);
Magick::Image img;
img.read(c);
img.write("logo.png");
}
catch (Exception &error_)
{
cout << "Caught exception: " << error_.what() << endl;
return 1;
}
return 0;
}
But while opening any image(img.read(c)) I get an error:
Caught exception: MyProject.exe: unable to open image `≡█I': No such file or directory # error/blob.c/OpenBlob/2695
Work with: ImageMagick-7.0.3-Q8, Windows 7 x64

Related

OPENCV: Fail to use dnn module in c++

I'm using dnn module in opencv.
Previously, it work well in python.
But when I turn to C++ version.readNetFromDarknet function report error that I don't know how to fix. Error is below:
Unhandled exception at 0x00007FFF37BE4F69 in untitled.exe: Microsoft C++ exception: std::out_of_range at memory location 0x000000BF2A53F090
My full code is :
#include <QCoreApplication>
#include <opencv2/opencv.hpp>
#include <string>
using namespace cv;
using namespace std;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
string classesFile, modelConfig, modelWeights;
classesFile = "D:/work/rs/model/guoxing_mac9_3535_20220224.names";
modelConfig = "D:/work/rs/model/guoxing_mac9_3535_20220224.cfg";
modelWeights = "D:/work/rs/model/guoxing_mac9_3535_20220224_last.weights";
dnn::Net m_model;
vector<string> m_classes;
ifstream ifs(classesFile.c_str());
string line;
while (getline(ifs, line))
m_classes.push_back(line);
try
{
cout << "trying" << endl;
m_model = dnn::readNetFromDarknet(modelConfig, modelWeights);
}
catch (Exception& e)
{
cout << e.msg << endl;
}
m_model.setPreferableBackend(dnn::DNN_BACKEND_OPENCV);
m_model.setPreferableTarget(dnn::DNN_TARGET_OPENCL);
return a.exec();
}
Test in Opencv3.4.2 and VS2017.
Thanks for all reply!
After update Opencv from 3.4.2 to 3.4.16, it solved. low version dnn module is not work well for some network architecture.

debug assertion failed error nptr!=NULL

I get an Debug Assertion Error with expression: nptr!=NULL
my code:
#include <iostream>
using namespace std;
void main(int argc, char* argv[])
{
cout << "Hello Number " << atoi(argv[1]) << endl;
}
can somebody please help me solve this?
Most likely explanation is that you're not passing any parameters to your program, such as you would with the command runme 7.
The argv[argc] string is required to be NULL so this would explain why the assertion is happening.
Check that you have the correct number of parameters before trying to use them:
#include <iostream>
#include <cstdlib>
using namespace std;
int main(int argc, char* argv[]) {
if (argc != 2) {
cerr << "Usage: runme <integer argument>" << endl;
return 1;
}
cout << "Hello Number " << atoi(argv[1]) << endl;
}

OpenCV 3.0.0 + VS 2015 x64 - frame always empty

I built OpenCV 3.0.0 for VS 2015 in Windows 10 Pro x64.
Then I compiled the following code:
#include "opencv2\opencv.hpp"
#include <iostream>
int main(int argc, char** argv){
cv::VideoCapture capture("Vid_A_ball.avi");
if (! capture.isOpened()){
std::cout << "Video Not Opened" << std::endl;
return -1;
}
cv::Mat frameReference;
while (true){
capture >> frameReference;
if (frameReference.empty()){
std::cout << "Capture Finished" << std::endl;
break;
} else {
cv::imshow("video", frameReference);
cv::waitKey(10);
}
}
return 0;
}
Video opened correctly, but frameReference.empty() is always true.
TIA,
horothesun.

OpenCV, C++ cvCaptureFromFile not working but Python VideoCapture is

Im working with some legacy code that I need to use, as well as do some work in Python. I am able to read from file in Python but not in C++. Here is the C++ code
int main(int argc, char** argv) {
CvCapture *capture = NULL;
capture = cvCaptureFromFile("path/to/foo.mov");
if (!capture) {
std::cerr << "Cannot open " << "path/to/foo.mov" << std::endl;
return 1;
}
return 0;
}

Thread exception when compiling this basic C++ code in Xcode

Everytime I compile this C++ code I get a thread exception I can't understand. What is wrong here?
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char* argv[]) {
string arg = argv[1];
if (arg == "-r")
cout << "First arg is -r" << endl;
return 0;
}
You forgot to check argc>=2 before assigning argv[1] to the string arg.
Are you sure you are running this program with passing a parameter?
A possible correction:
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char* argv[])
{
if(argc<2)
{
cerr << "Not enough parameters" << endl;
abort();
}
string arg = argv[1];
if (arg == "-r")
cout << "First arg is -r" << endl;
return 0;
}