Comments (6)
Out customer demands raw frame on Windows. We don't have time to investigate DirectShow. We are appreciated if OpenCV would provide an easy way.
from opencv.
Example code that works with my camera that supports MJPEG:
int main( int argc, char** argv )
{
cv::CommandLineParser parser(argc, argv, "{ c | 0 | }");
VideoCapture cap;
cap.open(parser.get<int>("c"), cv::CAP_V4L2);
cap.set(cv::CAP_PROP_FRAME_WIDTH, 1280);
cap.set(cv::CAP_PROP_FRAME_HEIGHT, 720);
cap.set(cv::CAP_PROP_CONVERT_RGB, 0);
cap.set(cv::CAP_PROP_FOURCC, cv::VideoWriter::fourcc('M', 'J', 'P', 'G') );
if (!cap.isOpened())
{
cerr << "Can't open camera/video stream!" << endl;
return 1;
}
cout << "Video " << parser.get<string>("c") <<
": width=" << cap.get(CAP_PROP_FRAME_WIDTH) <<
", height=" << cap.get(CAP_PROP_FRAME_HEIGHT) << endl;
namedWindow("Preview");
Mat result;
for(;;)
{
Mat frame;
cap >> frame;
if( frame.empty() )
break;
result = cv::imdecode(frame, cv::IMREAD_COLOR);
imshow("Preview", result);
char c = (char)waitKey(30);
if( c == 'q' || c == 'Q' || c == 27 )
break;
}
return 0;
}
from opencv.
It's not gonna work on Windows, right?
from opencv.
I have not tried (CAP_V4L2 - it's for Linux) . I'll take a look.
from opencv.
The following code works for my Logitech camera:
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
cv::CommandLineParser parser(argc, argv, "{ c | 0 | }");
VideoCapture cap;
cap.open(parser.get<int>("c"), cv::CAP_MSMF);
cap.set(cv::CAP_PROP_FRAME_WIDTH, 1280);
cap.set(cv::CAP_PROP_FRAME_HEIGHT, 720);
cap.set(cv::CAP_PROP_CONVERT_RGB, 0);
cap.set(cv::CAP_PROP_FOURCC, cv::VideoWriter::fourcc('N', 'V', '1', '2'));
if (!cap.isOpened())
{
cerr << "Can't open camera/video stream!" << endl;
return 1;
}
int width = cap.get(CAP_PROP_FRAME_WIDTH);
int height = cap.get(CAP_PROP_FRAME_HEIGHT);
cout << "Video " << parser.get<string>("c") <<
": width=" << width <<
", height=" << height << endl;
namedWindow("Preview");
Mat result;
for (;;)
{
Mat frame, reshaped;
cap >> frame;
if (frame.empty())
break;
//result = cv::imdecode(frame, cv::IMREAD_COLOR);
cout << frame.cols << "x" << frame.rows << "x" << frame.channels() << std::endl;
reshaped = frame.reshape(1, height + height/2);
cvtColor(reshaped, result, cv::COLOR_YUV2BGR_NV12);
if (result.empty())
{
cout << "Empty frame" << std::endl;
}
else
{
imshow("Preview", result);
}
char c = (char)waitKey(30);
if (c == 'q' || c == 'Q' || c == 27)
break;
}
return 0;
}
Media Foundation back-end supports RAW images from camera, but returns them as byte array with size 1xN instead of expected Wx(H+H/2) for NV12.
from opencv.
Fantastic! I'll try it ASAP.
from opencv.
Related Issues (20)
- There seems to be an issue with the parallel_for_ function in the parallel.cpp file.
- Add SIMD256 intrinsics to demosaicing
- 3rdparty/ ndsrvp and hal_rvv seeems no lincense files. HOT 5
- all: http://opencv.org/license.html returns 404 status. HOT 3
- Docs for Python imshow example improvement
- HWASan error in BufferArea tests HOT 3
- OpenCV 4.10.0 segfault when using OpenVINO 2024.0.0 HOT 2
- phaseCorrelate fails with larger 16bit images
- dnn 5.x with OpenVINO 2022.1 backend doesn't pass integer tests because of the NaryEltwise layer
- HWASan error in G-API core test HOT 1
- CMake Error at cmake/OpenCVDetectCUDAUtils.cmake:297 (list): list GET given empty list HOT 8
- error: (-216:No CUDA support) OpenCV was not built to work with the selected device. Please check CUDA_ARCH_PTX or CUDA_ARCH_BIN in your build configuration. in function 'initCUDABackend'a support HOT 2
- Cant install latest opencv due to undefined reference (libcublas)
- G-API error in VASObjectTracker test HOT 1
- G-API error in some PatternMatchingIntegrationE2E tests HOT 1
- Does OpenCV really support FFmpeg 5.0+ on Windows?
- opencv still uses Concurrency Runtime in parallel_for_xxx functions on Windows
- Inconsistent result from segmentation sample for u2netp model HOT 1
- Possible memory leak in fastNlMeansDenoisingColored
- Opencv 4.5.4 with Cuda Build Error HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from opencv.