OpenCV 3, Error when run the project with fontQt? - opencv

When I compile the project no errors, but when i run the project i have a problem with fontQt.
OpenCV Error: The function/feature is not implemented (The library is compiled without QT support) in fontQt, file /home/developer/opencv/modules/highgui/src/window.cpp, line 507
terminate called after throwing an instance of 'cv::Exception'
what(): /home/developer/opencv/modules/highgui/src/window.cpp:507: error: (-213) The library is compiled without QT support in function fontQt
Aborted (core dumped)
#include <iostream>
#include <string>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
void pushButtonCallBack(int, void *font);
Mat originImg, tmpImg;
string win_img = "win_img";
char msg[50];
int main(int argc, char** argv)
{
std::cout << "OpenCV add text to img..." << std::endl;
originImg = imread(argv[1],IMREAD_UNCHANGED);
if(originImg.empty())
{
cout << "url is not true" << endl;
return -1;
}
string AddText = "AddText";
string text= "Text";
cv::QtFont font = fontQt("Arail", 20, Scalar(255,0,0,0), QT_FONT_BLACK, QT_STYLE_NORMAL);
createButton(AddText, pushButtonCallBack, &font, QT_PUSH_BUTTON );
imshow(win_img,originImg);
waitKey(0);
return 0;
}
void pushButtonCallBack(int, void *font)
{
addText(originImg, "Click", Point(50,50), *(QtFont *)font);
imshow(win_img, originImg);
return;
}
this is my cmake file
cmake_minimum_required(VERSION 3.8)
project(lesson_3_3)
set(CMAKE_CXX_STANDARD 11)
find_package( OpenCV REQUIRED )
set(SOURCE_FILES main.cpp)
add_executable(lesson_3_3 ${SOURCE_FILES})
target_link_libraries( lesson_3_3 ${OpenCV_LIBS} )

Related

CNN model does not load inside Visual Studio 2017 using dnn.readNetFromTensorflow

I have created a simple CNN model which I froze into tf_model.pb file and I have tried loading it using open cv dnn.readNetFromTesnorflow(model_path) method inside Jupyter Notebook and it works perfectly. The problem is when I try to load it inside Visual Studio 2017, for some reason it does not load correctly.
Here is my code:
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/dnn.hpp>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
using namespace cv;
using namespace cv::dnn;
int main(int argc, char** argv) {
class CharNet {
private:
Net network;
string output_layer;
public:
CharNet(string path) {
try {
cout << "Path: "<< path << endl;
network = readNetFromTensorflow(path);
vector<String> network_layers = network.getLayerNames();
cout << "There are "<<network_layers.size()<< " layers" << endl;
for (int i = 0; i < network_layers.size(); i++) {
cout << network_layers[i] << endl;
if ( network_layers[i].find("Softmax") != std::string::npos ) {
cout << "Output Layer: "<< network_layers[i] << endl;
output_layer = network_layers[i];
break;
}
}
}
catch (cv::Exception& e) {
cerr << "Exception: " << e.what() << endl;
if (network.empty()) {
cerr << "Can't load the model" << endl;
}
}
}
};
string model = "C:/Users/stefan_cepa995/source/repos/OpenCV_Test/OpenCV_Test/tf_model.pb";
CharNet* obj = new CharNet(model);
return 0;
}
Since the model is not loaded correctly I never enter the for loop. Does anyone have any idea whats going on?

Image panorama stitching black spots

Maybe someone knows what can cause that problem.
I have a simple code for stitching 12 images in one panorama image, but faced with strange behaviour.
Here the result of stitching on my MacBook Pro:
https://drive.google.com/open?id=1f_7i_rb8pnbHEBxlowzFa13MAHvxN07u
And result of stitching on my Desktop Mac:
https://drive.google.com/open?id=19CoyPzz6QgDjqG1lUZbphGPYvCAg41hi
The code i used is the same and images same too. On my desktop mac i can build and run it without problems, but on my MacBook it not working at all, it shows me the next error:
OpenCV Error: Assertion failed (imgs.size() == imgs_.size())
in composePanorama, file /tmp/opencv-20171031-87373-6u1izq/opencv-3.3.1/modules/stitching/src/stitcher.cpp, line 168
libc++abi.dylib: terminating with uncaught exception of type cv::Exception: /tmp/opencv-20171031-87373-6u1izq/opencv-3.3.1/modules/stitching/src/stitcher.cpp:168:
error: (-215) imgs.size() == imgs_.size() in function composePanorama
This is my code:
#include <stdio.h>
#include <iostream>
#include <vector>
#include <opencv2/opencv.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/stitching.hpp>
using namespace std;
using namespace cv;
int main(int argc, char** argv ) {
vector<Mat> images_arr;
const string images[] = {
"/Users/george/CLionProjects/OpenCV_Stitch/test_stitch/1.jpeg",
"/Users/george/CLionProjects/OpenCV_Stitch/test_stitch/2.jpeg",
"/Users/george/CLionProjects/OpenCV_Stitch/test_stitch/3.jpeg",
"/Users/george/CLionProjects/OpenCV_Stitch/test_stitch/4.jpeg",
"/Users/george/CLionProjects/OpenCV_Stitch/test_stitch/5.jpeg",
"/Users/george/CLionProjects/OpenCV_Stitch/test_stitch/6.jpeg",
"/Users/george/CLionProjects/OpenCV_Stitch/test_stitch/7.jpeg",
"/Users/george/CLionProjects/OpenCV_Stitch/test_stitch/8.jpeg",
"/Users/george/CLionProjects/OpenCV_Stitch/test_stitch/9.jpeg",
"/Users/george/CLionProjects/OpenCV_Stitch/test_stitch/10.jpeg",
"/Users/george/CLionProjects/OpenCV_Stitch/test_stitch/11.jpeg",
"/Users/george/CLionProjects/OpenCV_Stitch/test_stitch/12.jpeg",
};
const char* outFile = "/Users/george/CLionProjects/OpenCV_Stitch/out.jpeg";
for(auto path : images) {
Mat image = imread(path, IMREAD_REDUCED_COLOR_2 | IMREAD_IGNORE_ORIENTATION);
images_arr.push_back(image);
}
Mat pano;
Stitcher stitcher = Stitcher::createDefault(false);
stitcher.setRegistrationResol(0.8);
stitcher.setSeamEstimationResol(0.1);
stitcher.setCompositingResol(1);
stitcher.setPanoConfidenceThresh(1);
stitcher.setWaveCorrection(true);
stitcher.setWaveCorrectKind(detail::WAVE_CORRECT_HORIZ);
Stitcher::Status status1 = stitcher.estimateTransform(images_arr);
Stitcher::Status status = stitcher.composePanorama(images_arr, pano);
if (status != Stitcher::OK) {
cout << "Can't stitch images, error code = " << int(status) << endl;
return -1;
}
imwrite(outFile, pano);
return 0;
}
My CmakeLists.txt configuration:
cmake_minimum_required(VERSION 3.8)
project(OpenCV_Stitch)
set(CMAKE_CXX_STANDARD 11)
find_package(OpenCV REQUIRED)
set(SOURCE_FILES main.cpp)
add_executable(OpenCV_Stitch ${SOURCE_FILES})
target_link_libraries(OpenCV_Stitch ${OpenCV_LIBS})
Can't even imagine what can cause that black spots on image. Did anyone come across this? And sometimes, when i use different images to stitch opencv returns error: Camera parameters adjusting failed
How can i prevent that? Maybe use some methods to estimate camera rotation or something like that?
Here the link to images what i try to stitch:
https://drive.google.com/open?id=1-DfSf8eaC7bi37-ZhBpaRt8jHVvO_Qwb
Thanks!
i get the same error message with your code. when i modified the part below it runs without error.
Mat pano;
Ptr<Stitcher> stitcher = Stitcher::create(Stitcher::PANORAMA, false);
stitcher->setRegistrationResol(0.8);
stitcher->setSeamEstimationResol(0.1);
stitcher->setCompositingResol(1);
stitcher->setPanoConfidenceThresh(1);
stitcher->setWaveCorrection(true);
stitcher->setWaveCorrectKind(detail::WAVE_CORRECT_HORIZ);
Stitcher::Status status = stitcher->stitch(images_arr, pano);

OpenCv 3.1.0 undefined reference to imread

This is what my code looks like, I got the undefined reference to imread and so on:
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main( int argc, const char** argv )
{
Mat img = imread("MyPicture.jpg", CV_LOAD_IMAGE_UNCHANGED); //read the image data in the file "MyPic.JPG" and store it in 'img'
if (img.empty()) //check whether the image is loaded or not
{
cout << "Error : Image cannot be loaded..!!" << endl;
//system("pause"); //wait for a key press
return -1;
}
namedWindow("MyWindow", CV_WINDOW_AUTOSIZE); //create a window with the name "MyWindow"
imshow("MyWindow", img); //display the image which is stored in the 'img' in the "MyWindow" window
waitKey(0); //wait infinite time for a keypress
destroyWindow("MyWindow"); //destroy the window with the name, "MyWindow"
return 0;
}
I am using Codeblocks and the g++ compiler. Also I have linked the opencv_world310d.lib to debug and opencv_world310.lib to release.
Plus I have given the path in searchdirectory compiler and linker.
Any hints?

opencv c++ HSV image channel separation exception

I know this question has been asked a number of times and I'm trying to implement their answers but its causing an exception in my code.
OS: Windows 7
OpenCV: 2.4.9
Here is my code:
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
VideoCapture cap(0); //capture the video from webcam
if ( !cap.isOpened() ) // if not success, exit program
{
cout << "Cannot open the web cam" << endl;
return -1;
}
Mat imgHSV;
_sleep(100); //give the camera a chance to wake up
while (true)
{
Mat imgOriginal;
bool success = cap.read(imgOriginal);
if (!success) //if not success, break loop
{
cout << "Cannot read a frame from video stream" << endl;
break;
}
cvtColor(imgOriginal, imgHSV, COLOR_BGR2HSV); //Convert the captured frame from BGR to HSV
vector<Mat> hsv_planes;
split( imgHSV, hsv_planes );
//hsv_planes[0] // H channel
//hsv_planes[1] // S channel
//hsv_planes[2] // V channel
imshow(thresholded_window, hsg_planes[2]); //show the S channel
if (waitKey(30) == 27) //wait for 'esc' key press for 30ms. If 'esc' key is pressed, break loop
{
cout << "esc key is pressed by user" << endl;
break;
}
}
return 0;
}
Exception is thrown on the split line: "Unhandled exception at 0x62B978C9 (opencv_core249.dll) in TrackColour.exe: 0xC0000005: Access violation writing location 0xFEEEFEEE."
I figured out my problem, incase this happens to anyone else.
In VS I was doing a debug build but I was linking to the non debug versions of opencv. Notice in my error message opencv_core249, it should have been opencv_core249d (Note the 'd'). I updated my CV linking to use the debug libraries and it works.
The other opencv calls performed fine using the wrong libraries, something must be unique with split.

cv.h: file not found opencv

I'm running this code:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main( int argc, char** argv ) {
if( argc != 2)
{
cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
return -1;
}
Mat image;
image = imread(argv[1], CV_LOAD_IMAGE_COLOR); // Read the file
if(! image.data ) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
namedWindow( "Display window", CV_WINDOW_AUTOSIZE );// Create a window for display.
imshow( "Display window", image ); // Show our image inside it.
waitKey(0); // Wait for a keystroke in the window
return 0; }
But it isn't working for me because it shows this error on my screen when I write cmake . in terminal:
cv.h: file not found.
Could anyone help me? It was working one month ago.
you have linking problem, try this out;
g++ `pkg-config --cflags --libs opencv` filename.cpp -o filename
You can change the linker properties in case of Visual studio.
For Makefile you need to make sure that the opencv_dir is set correctly.

Resources