我想通过以下代码从图像序列(在Android上)创建视频:
opencv_core.IplImage image = cvLoadImage("/sdcard/mytest/testimage.jpg");
FFmpegFrameRecorder recorder = new FFmpegFrameRecorder("/sdcard/mytest/test.3gp",256,256);
try {
recorder.setCodecID( CODEC_ID_H263);
recorder.setFormat("3gp");
recorder.setPixelFormat( PIX_FMT_YUV420P);
recorder.start();
for (int i=0;i<10;i++)
{
recorder.record(image);
}
recorder.stop();
}
catch (Exception e){
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
但我没有我的形象,我有绿屏.我的代码中需要更改什么?
以及如何为我的视频添加音频?
这段代码行的含义是什么?如何将此代码转换为javacv?
gray = Scalar::all(255);
Run Code Online (Sandbox Code Playgroud)
这是与此代码行相关的整个代码.
Mat src = imread("in.jpg"), gray;
cvtColor(src, gray, CV_BGR2GRAY);
threshold(gray, gray, 230, 255, THRESH_BINARY_INV);
vector<Vec4i> hierarchy;
vector<vector<Point> > contours;
findContours(gray, contours, hierarchy, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE);
gray = Scalar::all(255);
Run Code Online (Sandbox Code Playgroud)
有人可以解释一下吗?
是否有一个Java数组转换是一个简单的方法double[][]来CvMat在JavaCV?
我想在OpenCV中你可以说cv::Mat Table(8, 8, CV_32FC1, table);,table8x8阵列在哪里.但是在JavaCv中它不起作用.
我试图识别这个黑色多边形周围的轮廓,我需要访问这些点,但它不适合我.这是输入图像

但是,当我尝试执行以下代码时,它没有给出预期的结果,这意味着它应该.
CanvasFrame cnvs=new CanvasFrame("Polygon");
cnvs.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
CvMemStorage storage=CvMemStorage.create();
CvSeq squares = new CvContour();
squares = cvCreateSeq(0, sizeof(CvContour.class), sizeof(CvSeq.class), storage);
String path="project/Test/img/black.png";
IplImage src = cvLoadImage(path);
IplImage gry=cvCreateImage(cvGetSize(src),IPL_DEPTH_8U,1);
cvCvtColor(src, gry, CV_BGR2GRAY);
cvThreshold(gry, gry, 230, 255, CV_THRESH_BINARY_INV);
cnvs.showImage(gry);
cvFindContours(gry, storage, squares, Loader.sizeof(CvContour.class), CV_RETR_LIST, CV_CHAIN_APPROX_NONE);
CvSeq ss=null;
CvSeq tmp=null;
int ii=0;
for (ss=squares; ss!=null; ss=ss.h_next()) {
tmp=cvApproxPoly(ss, sizeof(CvContour.class), storage, CV_POLY_APPROX_DP, 8, 0);
System.out.println("index "+ii+" points "+tmp.total()+" area "+cvContourArea(ss, CV_WHOLE_SEQ, 0));
cvDrawContours(src, ss, CvScalar.RED, CV_RGB(248, 18, 18), 1, -1, 8);
//drawPoly(src, tmp);
}
IplConvKernel …Run Code Online (Sandbox Code Playgroud) 我正在尝试从数独板中提取数字。在检测到板子、它的角和变形后,我只剩下一个漂亮的板子图像。现在我正在尝试使用 Tesseract android 实现 Tess-Two 来识别数字。我将图像分成 9 个部分
currentCell = undistortedThreshed.submat(rect);
Run Code Online (Sandbox Code Playgroud)
哪里rect是围绕图像的矩形。
现在到数字识别。
有些数字,比如 4,它可以完美识别。一些,主要是 6,7,8 被识别为 0 或什么都没有。
我想通过清理currentCell图像来帮助尽可能多地进行 tesseract 。目前它看起来像这样
. (也试过没有倒置阈值)。我想摆脱白线(数独线)。我试过这样的事情(取自here)
Imgproc.Canny(currentCell, currentCell, 80, 90);
Mat lines = new Mat();
int threshold = 50;
int minLineSize = 5;
int lineGap = 20;
Imgproc.HoughLinesP(currentCell, lines, 1, Math.PI / 180,
threshold, minLineSize, lineGap);
for (int x = 0; x < lines.cols() && x < 1; x++) {
double[] vec = lines.get(0, x);
double …Run Code Online (Sandbox Code Playgroud) 我正在尝试制作一个从网络摄像头拍摄照片的程序,然后调整它的大小,将其转换为HSV,并对其进行一些阈值处理,以找到特定的颜色.完成此操作后,我使用阈值图像查找轮廓,并打印不同轮廓的x,y坐标.这反复重复,以实时从网络摄像头进行处理.
这一切都运行得很好,除了我每2秒运行大约100 MB RAM的事实.
到目前为止,我发现如果我使用静态图片,而不是网络摄像头的实时图像,我可以显着减少内存泄漏,尽管仍然有内存消耗.
我的代码下面是:
public class Application {
private CaptureImage ci;
private ImageUtils iu;
private CanvasFrame canvasContours;
IplImage grabbedFrame;
IplImage resizedFrame;
IplImage thresholdedFrame;
IplImage clonedImage;
public Application(){
ci = new CaptureImage();
iu = new ImageUtils();
canvasContours = new CanvasFrame("contours");
}
public void frameProcessing(){
grabbedFrame = ci.grabImage();
//below call used for testing purposes
//grabbedFrame = (IplImage) opencv_highgui.cvLoadImage("testingImage.jpg");
//cloning image due to highgui guidelines.
clonedImage = opencv_core.cvCloneImage(grabbedFrame);
resizedFrame = iu.resizeImage(clonedImage);
opencv_core.cvReleaseImage(clonedImage);
thresholdedFrame = iu.thresholdImage(resizedFrame);
IplImage contoursFrame = iu.findContours(thresholdedFrame, resizedFrame);
canvasContours.showImage(contoursFrame); …Run Code Online (Sandbox Code Playgroud) 我创建了一个从视频中捕获帧的类.捕获帧时,它将保存为图片.当视频是.avi时,应用程序运行正常.格式为.avi时.
public static void main(String[] args) {
FFmpegFrameGrabber grabber = new FFmpegFrameGrabber("C:/Users/Ioanna/Desktop/video1.avi");
try {
IplImage img;
//Start grabber to capture video
grabber.start();
//grab video frame to IplImage
img = grabber.grab();
if (img != null) {
//save video frame as a picture
cvSaveImage("capture.jpg", img);
}
}catch (Exception e) {
}
}
Run Code Online (Sandbox Code Playgroud)
错误是
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.googlecode.javacv.FFmpegFrameGrabber.<init>(FFmpegFrameGrabber.java:106)
at Video.main(Video.java:75)
Caused by: java.lang.IllegalStateException: Can't overwrite cause with java.lang.UnsatisfiedLinkError: no avcodec in java.library.path
at java.lang.Throwable.initCause(Throwable.java:457)
at com.googlecode.javacpp.Loader.load(Loader.java:581)
at com.googlecode.javacpp.Loader.load(Loader.java:532)
at com.googlecode.javacv.cpp.avcodec.<clinit>(avcodec.java:39) …Run Code Online (Sandbox Code Playgroud) 我正在编写一个使用 JavaCV 进行面部识别的 Android 应用程序。我所遇到的一个小问题,我需要转换从org.opencv.core.Mat该onCameraFrame(CvCameraViewFrame inputFrame)函数返回到org.bytedeco.javacpp.opencv_core.Mat的org.bytedeco.javacpp.opencv_contrib.FaceRecognizer需要。
我来自使用Android MediaCodec从相机编码H.264的线程。我的设置非常相似。但是,我尝试使用javacv编写编码帧的多路复用,并通过rtmp广播它们。
RtmpClient.java
...
private volatile BlockingQueue<byte[]> mFrameQueue = new LinkedBlockingQueue<byte[]>(MAXIMUM_VIDEO_FRAME_BACKLOG);
...
private void startStream() throws FrameRecorder.Exception, IOException {
if (TextUtils.isEmpty(mDestination)) {
throw new IllegalStateException("Cannot start RtmpClient without destination");
}
if (mCamera == null) {
throw new IllegalStateException("Cannot start RtmpClient without camera.");
}
Camera.Parameters cameraParams = mCamera.getParameters();
mRecorder = new FFmpegFrameRecorder(
mDestination,
mVideoQuality.resX,
mVideoQuality.resY,
(mAudioQuality.channelType.equals(AudioQuality.CHANNEL_TYPE_STEREO) ? 2 : 1));
mRecorder.setFormat("flv");
mRecorder.setFrameRate(mVideoQuality.frameRate);
mRecorder.setVideoBitrate(mVideoQuality.bitRate);
mRecorder.setVideoCodec(avcodec.AV_CODEC_ID_H264);
mRecorder.setSampleRate(mAudioQuality.samplingRate);
mRecorder.setAudioBitrate(mAudioQuality.bitRate);
mRecorder.setAudioCodec(avcodec.AV_CODEC_ID_AAC);
mVideoStream = new VideoStream(mRecorder, mVideoQuality, mFrameQueue, mCamera);
mAudioStream = new AudioStream(mRecorder, mAudioQuality); …Run Code Online (Sandbox Code Playgroud) 我们正在尝试从视频创建缩略图。我们尝试了两个第三方库。那些是
那些工作正常。但是我们正在尝试Java内置库。我们找到了一个Java库,那就是
javax.media。*
但是该库已贬值。我们无法使用它。
我们是否有针对此问题的Java内置库?