I'm trying to open an avi file using openCV:
int main(int argc, char *argv[])
{
const string path = "C:\\Users\\name\\file.avi";
VideoCapture captRefrnc(path);
if (!captRefrnc.isOpened())
{
cout << "Could not open reference " << endl;
return -1;
}
}
However, the output is the following:
[ERROR:0] global C:\build\master_winpack-build-win64-vc15\opencv\modules\videoio\src\cap.cpp (166) cv::VideoCapture::open VIDEOIO(CV_IMAGES): raised OpenCV exception:
OpenCV(4.5.4) C:\build\master_winpack-build-win64-vc15\opencv\modules\videoio\src\cap_images.cpp:235: error: (-5:Bad argument) CAP_IMAGES: error, expected '0?[1-9][du]' pattern, got: h¾∟#± in function 'cv::icvExtractPattern'
[ERROR:0] global C:\build\master_winpack-build-win64-vc15\opencv\modules\videoio\src\cap.cpp (175) cv::VideoCapture::open VIDEOIO(CV_MJPEG): raised C++ exception:
string too long
Could not open reference
I do not understand what this means though? Can openCV just not handle .avi files?
Related
I'm making a calculator using the command line and am using a stack to push the values of the arguments (digits of the calculator and operators), but I keep getting an invalid conversion from 'char*' to 'std::stack""value_type' and "no matching function for call to 'push(char*&)' error. Any ideas on what im doing wrong?
My code:
#include <iostream>
#include <cmath>
#include <stack>
int main(int argc,char* argv[])
{
std::stack<int> numbers;
// std::stack<char> operators;
for(int i=1;i<argc;++i)
{
numbers.push(argv[i]);
//operators.push(argv[i+1]);
}
while(!numbers.empty())
{
std::cout << numbers.top() << std::endl;
numbers.pop();
// std::cout << operators.top() << std::endl;
// operators.pop();
}
return 0;
I've tried using & and * and $ to try to call the values but I just don't think I'm getting something.
I am trying to convert a DICOM file into PLY format using VTK to further convert it into .pcd (point cloud format). I have followed the example provided here.
However in the above example the code is supposed to change .vtu format into .ply format. I changed the code to convert the .dcm format into .ply format as shown below. The build succeeded and the exe file is working as well, however, it does not write the required output file. Can anyone please point out where did I go wrong??
#include <vtkSmartPointer.h>
#include <vtkPolyData.h>
#include <vtkDICOMImageReader.h>
#include <vtkXMLPolyDataReader.h>
#include <vtkPLYWriter.h>
int main(int argc, char *argv[])
{
if(argc < 3)
{
std::cerr << "Required arguments: input.vtp output.ply" << std::endl;
return EXIT_FAILURE;
}
std::string inputFileName = argv[1];
std::string outputFileName = argv[2];
// Read the DICOM file in the specified directory.
vtkSmartPointer<vtkDICOMImageReader> reader =
vtkSmartPointer<vtkDICOMImageReader>::New();
reader->SetFileName(inputFilename.c_str());
reader->Update();
vtkSmartPointer<vtkPLYWriter> writer = vtkSmartPointer<vtkPLYWriter>::New();
writer->SetFileName(outputFileName.c_str());
writer->SetInputConnection(reader->GetOutputPort());
writer->Update();
return EXIT_SUCCESS;
}
Below is an example of a simple contouring of a DICOM file and extraction of the largest connected area of polydata from the Marching Cubes filter then saved as a PLY format file. This should answer your question.
`
#include <vtkSmartPointer.h>
#include <vtkPolyData.h>
#include <vtkDICOMImageReader.h>
#include "vtkMarchingCubes.h"
#include "vtkPolyDataConnectivityFilter.h"
#include <vtkPLYWriter.h>
int main(int argc, char *argv[])
{
if(argc < 3)
{
std::cerr << "Required arguments: input.dcm output.ply" << std::endl;
return EXIT_FAILURE;
}
std::string inputFileName = argv[1];
std::string outputFileName = argv[2];
// Read the DICOM file in the specified directory.
vtkSmartPointer<vtkDICOMImageReader> reader =
vtkSmartPointer<vtkDICOMImageReader>::New();
reader->SetFileName(inputFilename.c_str());
reader->Update();
//arb. threshold for bone based on CT Hounsfield Units
float isoValue = 400.0
vtkSmartPointer<vtkMarchingCubes> surface = vtkSmartPointer<vtkMarchingCubes>::New();
surface->SetInputConnection(reader->GetOutputPort());
surface->ComputeNormalsOn();
surface->SetValue(0, isoValue);
surface->Update()
// To remain largest region
vtkSmartPointer<vtkPolyDataConnectivityFilter> confilter =
vtkSmartPointer<vtkPolyDataConnectivityFilter>::New();
confilter->SetInputConnection(surface->GetOutputPort());
confilter->SetExtractionModeToLargestRegion();
confilter->Update();
vtkSmartPointer<vtkPLYWriter> writer = vtkSmartPointer<vtkPLYWriter>::New();
writer->SetFileName(outputFileName.c_str());
writer->SetInputConnection(confilter->GetOutputPort());
writer->Update();
return EXIT_SUCCESS;
}
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} )
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?
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.