Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions common-mod/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ repositories {
}
}

compileJava.dependsOn(':common:shadowJar')

dependencies {
implementation("org.openpnp:opencv:${opencv_version}")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public void run() {
int realWidth = 0, realHeight = 0;
int lastFps = 0;
int realFps = 0;
boolean formatChecked = false;

VideoCapture cap = new VideoCapture(deviceNumber);
Mat mat = new Mat();
Expand All @@ -72,6 +73,7 @@ public void run() {
cap.set(CAP_PROP_FRAME_HEIGHT, resolution.height);
realWidth = (int) Math.round(cap.get(CAP_PROP_FRAME_WIDTH));
realHeight = (int) Math.round(cap.get(CAP_PROP_FRAME_HEIGHT));
formatChecked = false;
}
int fps = this.fps;
if (lastFps != fps) {
Expand All @@ -82,6 +84,17 @@ public void run() {
if (!cap.read(mat)) {
throw new DeviceException(Component.translatable("webcam.error.device_disconnected", deviceNumber));
}

if (!formatChecked) {
formatChecked = true;
org.opencv.core.Scalar sum = org.opencv.core.Core.sumElems(mat);
// Some virtual cameras (OBSBOT) output NV12 which DSHOW can't convert to RGB, causing black frames.
// Detect this and force NV12 format explicitly.
if (mat.channels() == 3 && sum.val[0] == 0 && sum.val[1] == 0 && sum.val[2] == 0) {
cap.set(CAP_PROP_FOURCC, org.opencv.videoio.VideoWriter.fourcc('N', 'V', '1', '2'));
}
}

onFrame(realFps, realWidth, realHeight, mat);
}
} finally {
Expand Down
2 changes: 2 additions & 0 deletions paper/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ repositories {
}
}

compileJava.dependsOn(':common:shadowJar')

dependencies {
implementation "io.netty:netty-handler:${netty_version}"
implementation "io.netty:netty-buffer:${netty_version}"
Expand Down