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.
Related
Visual Studio and opencv are using versions 2019 and 4.4.0
GoPRO HERO 7 BLACK is connected to PC using USB-C.
I try to open the cam using VideoCapture(), but it is not opened.
Below is the code are using.
#include <opencv2\opencv.hpp>
#include <opencv2\highgui.hpp>
#include <opencv2\core.hpp>
#include <opencv2\imgproc.h>>
using namespace cv;
using namespace std;
int main(void) {
VideoCpature webcam_01(0);
if(!webcam_01.isOpened()) {
cout << "Cam opened error" << endl;
return -1; }
while(1) {
Mat frame;
webcam_01.read(frame);
if(frame.empty()) {
cout << "frame empty" << endl;
break;
}
imshow("img", frame);
}
return 0;
}
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
I have OpenCV-2.4.9 installed in Raspberry Pi. Right now I am trying to load a video from specific path and for that I tried with both C and C++ API
C API: cvCaptureFromFile(path);
C++ API: VideoCapture cap; cap.open(path)
I am getting error and it says could not open file.
It works well in Windows and Linux, but not in Raspberry Pi. Am I missing something?
C++ code:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
int main(){
VideoCapture cap("C:/Users/nava/Videos/file.mp4");
if (!cap.isOpened()){
cout << "Error opening video stream" << endl;
return -1;
}
while (1){
Mat Frame;
if (!cap.read(Frame)){
cout << "No Frame available" << endl;
waitKey();
}
imshow("output", Frame);
if (waitKey(33) == 27) break;
}
}
C Code:
#include "highgui.h"
int main(int argc, char** argv)
{
cvNamedWindow("video",CV_WINDOW_AUTOSIZE);
CvCapture* capture = cvCreateFileCapture("/home/pi/Desktop/test.mp4");
IplImage* frame;
while(1)
{
frame = cvQueryFrame(capture);
if(!frame) break;
cvShowImage("video", frame);
char c = cvWaitKey(33);
if(c == 27) break;
}
}
You have to install UV4L driver.Follow this tutorial :
http://www.linux-projects.org/modules/sections/index.php?op=viewarticle&artid=14
I am trying to write a program that captures video from a webcam using 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)
{
Mat frame;
VideoCapture cap(1);
char key;
String outputName = "output.avi";
VideoWriter outputVideo;
Size size = Size(cap.get(CV_CAP_PROP_FRAME_WIDTH), cap.get(CV_CAP_PROP_FRAME_HEIGHT));
outputVideo.open(outputName, CV_FOURCC('D', 'I', 'V', 'X'), cap.get(CV_CAP_PROP_FPS), size, true);
if (!outputVideo.isOpened())
{
cout << "Could not open the output video for write: " << outputName << endl;
return -1;
}
cout << "size " << size.width << " x " << size.height << endl;
namedWindow("Display window", WINDOW_AUTOSIZE); // Create a window for display.
cap.set(CV_CAP_PROP_EXPOSURE, -8);
while (true){
bool success = cap.read(frame);
if (!success){
cout << "Cannot read frame from file" << endl;
return -2;
}
outputVideo.write(frame);
imshow("Display window", frame);
key = waitKey(1);
if (key == ' '){
cout << "Video ended due to key stroke" << endl;
return 1;
}
}
return 0;
}
The program doesn't seem to be able to open outputVideo since it always returns -1. I thought that I might not have the codec divx installed, but I have installed it from k-lite codec pack and divx and it still does not work.
Could anybody please tell me how to install codecs such that opencv recognizes them?
I am using OpenCV 2.4.10 on Windows 7 with Visual studio 2013.
I'm trying to make this simple GraphicsMagick example as a node binding/addon. This code works as expected in OSX 10.6.7 with GraphicsMagick 1.3.15
#include <Magick++.h>
#include <iostream>
using namespace std;
int main(int argc,char **argv)
{
Magick::InitializeMagick(0);
Magick::Image image;
try {
image.read( "snow.jpg" );
image.scale("320");
image.write( "snow-scaled.jpg" );
}
catch( Magick::Exception &error_ ) {
cout << "Caught exception: " << error_.what() << endl;
return 1;
}
cout << "Image scaled!" << endl;
return 0;
}
Compiling:
g++ scale.cpp `GraphicsMagick++-config --cppflags --cxxflags --ldflags --libs`
Running:
./a.out
Image scaled!
But making this code a node binding (0.6.14) just freezes (see full gist):
void AsyncWork(uv_work_t* req) {
std::cout << "AsyncWork..." << std::endl;
Baton* baton = static_cast<Baton*>(req->data);
baton->result = 12345; // Just a test
Magick::Image image; // <--- Freezes here!
image.read("snow.jpg");
std::cout << "Scaling..." << std::endl;
image.scale("200");
std::cout << "Done!" << std::endl;
image.write("snow-scaled.jpg");
// and baton->error to true.
}
Output when calling it from javascript:
AsyncWork...
Any ideas what's wrong?
On a side note, this actually works when compiled/run under Ubuntu!
Have you tried to initialise with Magick::InitializeMagick(0); in AsyncWork? Asynch functions run on pool threads.
You could always just git the finished GM addon here.