Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Java VideoCapture buffered stream constructor#27284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
asmorkalov merged 17 commits intoopencv:4.xfromdkurt:java_video_capture_read
May 14, 2025
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
17 commits
Select commitHold shift + click to select a range
1f1cd89
initial commit
dkurtMay 2, 2025
17b2886
dummy java wrapper
dkurtMay 2, 2025
cb2e2a9
Keep jclass in wrapper
dkurtMay 3, 2025
66cc8c5
working test
dkurtMay 5, 2025
8a44f4f
Revert unused files
dkurtMay 5, 2025
a52ebc9
Remove size argument from read
dkurtMay 5, 2025
b6faec7
Check backend available before test
dkurtMay 5, 2025
4822844
Try print exception
dkurtMay 6, 2025
c499ed2
Revert "Try print exception"
dkurtMay 6, 2025
faddefc
Use NewLocalRef for Java stream object
dkurtMay 6, 2025
eed126c
Wrap native seek and read
dkurtMay 7, 2025
a603bce
Try create global ref
dkurtMay 7, 2025
79afad9
Fix long long in Python
dkurtMay 7, 2025
b9b0310
Default IStreamReader constructor
dkurtMay 12, 2025
feee794
Use JavaVM
dkurtMay 12, 2025
f9cb6d4
Add AttachCurrentThread in case of JNI_EDETACHED error
dkurtMay 13, 2025
c3be053
Add constructor note
dkurtMay 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
working test
  • Loading branch information
@dkurt
dkurt committedMay 5, 2025
commit66cc8c5cf0b6649a30f9afffc367335e70c94c66
2 changes: 1 addition & 1 deletionmodules/videoio/misc/java/gen_dict.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@
"jn_type": "IStreamReader",
"jni_name": "n_%(n)s",
"jni_type": "jclass",
"jni_var": "auto n_%(n)s = makePtr<JavaStreamReader>(source)",
"jni_var": "auto n_%(n)s = makePtr<JavaStreamReader>(env,source)",
"j_import": "org.opencv.videoio.IStreamReader"
}
}
Expand Down
23 changes: 18 additions & 5 deletionsmodules/videoio/misc/java/src/cpp/videoio_converters.hpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,33 @@
#pragma once

class JavaStreamReader : public cv::IStreamReader
{
public:
JavaStreamReader(jclass _jobject) : jobject(_jobject) {}
JavaStreamReader(JNIEnv* _env,jclass _jobject) : env(_env), jobject(_jobject) {}

long long read(char* buffer, long long size) CV_OVERRIDE
{
printf("native read\n");
return 0;
jmethodID m_read = env->GetMethodID(env->GetObjectClass(jobject), "read", "([BJ)J");
if (!m_read)
return 0;
jbyteArray jBuffer = env->NewByteArray(size);
if (!jBuffer)
return 0;
jlong res = env->CallIntMethod(jobject, m_read, jBuffer, size);
env->GetByteArrayRegion(jBuffer, 0, size, reinterpret_cast<jbyte*>(buffer));
return res;
}

long long seek(long long offset, int way) CV_OVERRIDE
{
printf("native seek\n");
return 0;
jmethodID m_seek = env->GetMethodID(env->GetObjectClass(jobject), "seek", "(JJ)J");
if (!m_seek)
return 0;
jlong res = env->CallIntMethod(jobject, m_seek, offset, way);
return res;
}

private:
JNIEnv* env;
jclass jobject;
};
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
package org.opencv.videoio;

public interface IStreamReader {
public int seek(int offset, int origin);
public long read(byte[] buffer, long size);
public long seek(long offset, long origin);
}
61 changes: 51 additions & 10 deletionsmodules/videoio/misc/java/test/VideoCaptureTest.java
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,41 @@
package org.opencv.test.videoio;

import java.util.List;
import java.io.File;
import java.io.RandomAccessFile;
import java.io.IOException;
import java.io.FileNotFoundException;

import org.opencv.core.Mat;
import org.opencv.core.Size;
import org.opencv.core.MatOfInt;
import org.opencv.videoio.Videoio;
import org.opencv.videoio.VideoCapture;
import org.opencv.videoio.IStreamReader;

import org.opencv.test.OpenCVTestCase;

public class VideoCaptureTest extends OpenCVTestCase {
private final static String ENV_OPENCV_TEST_DATA_PATH = "OPENCV_TEST_DATA_PATH";

private VideoCapture capture;
private boolean isOpened;
private boolean isSucceed;
private File testDataPath;

@Override
protected void setUp() throws Exception {
super.setUp();

capture = null;
// isTestCaseEnabled = false;
isSucceed = false;
isOpened = false;

String envTestDataPath = System.getenv(ENV_OPENCV_TEST_DATA_PATH);

if(envTestDataPath == null) throw new Exception(ENV_OPENCV_TEST_DATA_PATH + " has to be defined!");

testDataPath = new File(envTestDataPath);
}

// public void testGrab() {
Expand DownExpand Up@@ -62,21 +75,49 @@ protected void setUp() throws Exception {
// assertNotNull(capture);
// }

public void testConstructorStream() {
public void testConstructorStream() throws FileNotFoundException {
RandomAccessFile f = new RandomAccessFile(new File(testDataPath, "cv/video/768x576.avi"), "r");

IStreamReader stream = new IStreamReader() {
// @Override
// public int read(String buffer, int size) {
// return 0;
// }
@Override
public long read(byte[] buffer, long size) {
try
{
return f.read(buffer);
}
catch (IOException e)
{
System.out.println(e.getMessage());
return 0;
}
}

@Override
public int seek(int offset, int origin) {
System.out.println("java seek");
return 0;
public long seek(long offset, long origin) {
try
{
if (origin == 0)
{
f.seek(offset);
return offset;
}
else
throw new IOException("seek");
}
catch (IOException e)
{
System.out.println(e.getMessage());
return 0;
}
}
};
capture = new VideoCapture(stream, Videoio.CAP_ANY, null);
capture = new VideoCapture(stream, Videoio.CAP_FFMPEG, new MatOfInt());
assertNotNull(capture);
assertTrue(capture.isOpened());

Mat frame = new Mat();
assertTrue(capture.read(frame));
assertEquals(frame.rows(), 576);
assertEquals(frame.cols(), 768);
}
}

[8]ページ先頭

©2009-2025 Movatter.jp