I've written an OpenCV code to evaluate NN for its capability of classification for segmenting. It took a long time to get the result for a small portion of code to be executed; due to the high availability of Microsoft Azure, it would be a chance to increase the pace for modeling.
I am interested in how to run this cpp OpenCV code on Azure cloud, including how to transfer cpp code and some training and test images on Azure. My code is long and though it is not included here but I can send the link if needed.
I've googled for how to use Microsoft Azure with cpp OpenCV but since I'm not much into cloud stuff and Azure explanations are confusing, I really appreciate any help with images or recorded screen showing the solution.
Based on Azure documentation, I need to a serverless framework to host code execution only.
Below is an intuitive OpenCV code and I am seeking a way to execute this. It reads an image, converts it to HSV, and saves something in an XML file.
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/imgcodecs.hpp>
#include <fstream>
using namespace cv;
using namespace std;
Mat image;
int main()
{
//read an image
image = imread("water (8).png", 1);
//check for existance of data
if (!image.data)
{
printf("no image data.\n"); return -1;
}
if (image.isContinuous()) {
cout << "loaded image is continuous" << "\n";
}
// hold HSV conversion of image
Mat HSVimage;
// convert to hsv - 0 < hsvimage < 255
cv::cvtColor(image, HSVimage, cv::COLOR_BGR2HSV);
FileStorage PrintInXMLFile("results.xml", FileStorage::WRITE);
PrintInXMLFile << "some_text" << "Hello!";
PrintInXMLFile.release();//release the file after writing
cv::waitKey(0);
return 0;
}// end main
Related
i have tried out almost every format of writing path of that specific image in my code(/,//), even tried out by putting the image into project folder with some respective changes. but still there is an assertion error(without if condition).I tried my best to solve this but still the image not opening. I am a newbie using OpenCV c++ . Please help me I am tired with this error.
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main()
{
Mat img = imread("test.png");
if (!img.data)
{
std::cout << "Image not loaded";
return -1;
}
imshow("Display Image", img);
waitKey(5000);
return 0;
}
I have 400x400 photo. I took the pieces as 4 separate photos of 100 * 400 and recorded them as 1, 2, 3, 4.jpg.
I have to combine 4 images croped from the one photo and get the original photo of 400 * 400. How can I do it ?
I don't want to use a ready(set) function. I need to do with for loop.
This is not going to be easy. Just reading a JPG without using a library could take weeks or months for a professional.
You should use a library. I would recommend CImg from here as a good starting point.
Failing that, I would suggest using ImageMagick to convert your JPGs to NetPBM PPM format then you can read them much more easily.
magick 1.jpg -depth 8 1.ppm
When you have written the code to combine them, you can convert the combined PPM file back into a JPG with:
magick combined.ppm combined.jpg
If you don't want to use available functions, you can create a 400x400 mask and assign the pixel values of each piece to the mask.
Here is the code:
#include <opencv2/highgui.hpp>
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main() {
// 4 Pieces
Mat piece_1 = imread("/ur/image/directory/1.jpg",CV_LOAD_IMAGE_GRAYSCALE);
Mat piece_2 = imread("/ur/image/directory/2.jpg",CV_LOAD_IMAGE_GRAYSCALE);
Mat piece_3 = imread("/ur/image/directory/3.jpg",CV_LOAD_IMAGE_GRAYSCALE);
Mat piece_4 = imread("/ur/image/directory/4.jpg",CV_LOAD_IMAGE_GRAYSCALE);
// Mask
Mat source_image = Mat::zeros(Size(400,400),CV_8UC1);
for(int i=0;i<source_image.rows;i++)
{
for(int j=0;j<source_image.cols;j++)
{
if(i<=99)
source_image.at<uchar>(i,j)=piece_1.at<uchar>(i,j);
if(i>99 && i<=199)
source_image.at<uchar>(i,j)=piece_2.at<uchar>(i-100,j);
if(i>199 && i<=299)
source_image.at<uchar>(i,j)=piece_3.at<uchar>(i-200,j);
if(i>299 && i<=399)
source_image.at<uchar>(i,j)=piece_4.at<uchar>(i-300,j);
}
}
imshow("Result",source_image);
waitKey(0);
return 0;
}
I want to display the image on any computer that opens the program .. But the software shows the picture only that the image and the software are in the same place (I want the image to be inside the software)
And if it is not in the same place then it shows me this error: (image)
https://i.imgur.com/bEtdaif.png
#include <iostream>
#include <Windows.h>
#include <opencv2/opencv.hpp>
#include "opencv2\highgui.hpp"
using namespace std;
using namespace cv;
int main()
{
Mat img = imread("d.png");
namedWindow("Image");
imshow("Image", img);
waitKey(0);
cout << "h";
int i;
cin >> i;
}
One way is to write a program that converts the image to a string of the form std::vector<uint8_t> image{ 0x01, 0x02 ... }; list each byte. Then save that string in a file.
Then #include that file into your program and read the image data from the image variable.
This way the image will be embedded in your executable by the compiler.
I am new to OpenCV. I appreciate if somebody answers this question. I try to read an image and display it. Below is a copy of the code I copied from documentation. However, a window just pops up without the actual image:
#include "opencv2/opencv.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
Mat img = imread("myimage.jpg", CV_LOAD_IMAGE_UNCHANGED);
if (img.empty())
{
cout << "Error : Image cannot be loaded..!!" << endl;
return -1;
}
else
{
namedWindow("MyWindow", CV_WINDOW_AUTOSIZE);
imshow("MyWindow", img);
waitKey(5000);
}
return 0;
}
I have copied over your code, and changed the image to my local one, and it displays correctly.
Looks like the program cannot read the image for some reason.
Why don't you try with the full path to the image?
The code is pretty correct, make sure you got myimage.jpg in the same folder with your binary.
Try with full path to an image or provide a path to your image as argv[1].
I wrote a simple program in OpenCV that detects SURF feature in a given image and diplays the detected features in a namedWindow.
#include <iostream>
#include <opencv2\core\core.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\features2d\features2d.hpp>
using namespace cv;
int main(int argc,char** argv)
{
if(argc!=3)//Check cmd number of argumets
{
std::cout<<"Usage: "<<argv[0]<<" <image-file> <method>"<<std::endl;
return -1;
}
//LOAD THE SOURCE IMAGE
Mat Img = imread(argv[1],CV_LOAD_IMAGE_GRAYSCALE);
if(!Img.data)//Check correct image load
{
std::cout<<"Cannot read image file. Check file path!"<<std::endl;
return -1;
}
//COMPUTE FEATURES
SurfFeatureDetector detector;
std::vector<KeyPoint> features;
detector.detect(Img,features);
//SHOW RESULT
Mat ImgF;
drawKeypoints(Img,features,ImgF);
namedWindow("Features", CV_GUI_NORMAL);
imshow("Features",ImgF);
waitKey();
return 0;
}
Everything is OK, the programs do what it have to do. The problem is when pressing a key to terminate the program a crash error occurs.
It doesn't crash for me... but in order for me to compile your code, I had to add
#include <opencv2/nonfree/features2d.hpp>
because SURF was moved to the nonfree module at some point.
So, I would have to recommend trying the newest version (2.4.6 as of today).