【发布时间】:2026-01-19 03:15:01
【问题描述】:
我有一个需要使用相机的俄罗斯方块项目。也就是说,有两个窗口。一个加载网络摄像头(OpenCV)并检测到红色三角形或正方形。另一个窗口是俄罗斯方块游戏(OpenGL),每个瓷砖都会从上到下一个接一个地下来。 所有功能都已编写好,一切正常。现在我需要将两者连接起来。 我在这里写了类的部分代码 在 BoxLightTextRendererPP 类中,您可以看到游戏块的定位。 在 VideoProcessing 类中,您可以看到相机的轮廓检测。 在 InteractionHandler 类中,我必须编写一个方法,例如使用 Switch-Case 检测到它,如果相机看到一个正方形,则将令牌向左移动,如果检测到三角形,则将其向右移动。 我该怎么做?
BoxLightTexRendererPP:
// Pointers (names) for data transfer and handling on GPU
private int[] vaoName; // Name of vertex array object
private int[] vboName; // Name of vertex buffer object
private int[] iboName; // Name of index buffer object
float[] barrey = verticies;
int block = 28;
//Startpunkt rechts/links
static float x = -1.5f;
//Startpunkt oben/unten
float h = 1.5f;
//Startpunkt vorne/hinten
float y = 0;
//Fallgeschwindigkeit
float fall = 0.01f;
boolean start = true;
public static boolean go = false;
boolean stay = false;
float[] barrey1 = verticies;
int block1 = 28;
视频处理:
for (int idx = 0; idx < contours.size(); idx++) {
MatOfPoint2f approx = new MatOfPoint2f(); //approx parameter count contours of objects; important for interaction handling
//allows the approximation of polygons and determine scope of object
Imgproc.approxPolyDP(newContours.get(idx), approx, Imgproc.arcLength(newContours.get(idx), true) * 0.02, true);
long count = approx.total();
//filtering small blobs
if(Math.abs(Imgproc.contourArea(contours.get(idx))) > 1000) {
//draw contours on objects
if (count == 5) {
Imgproc.drawContours(frame, contours, idx, new Scalar(75, 0, 0));
}
if (count == 6) {
Imgproc.drawContours(frame, contours, idx, new Scalar(255, 255, 255));
}
if (count == 4) {
Imgproc.drawContours(frame, contours, idx, new Scalar(200, 0, 0));
viereck = (int) count;
}
if (count == 3) {
Imgproc.drawContours(frame, contours, idx, new Scalar(360, 100, 50));
dreieck = (int) count;
}
}
}
交互处理程序:
public void connection() {
float xAchse = BoxLightTexRendererPP.x;
int viereck = VideoProcessing.viereck;
int dreieck = VideoProcessing.dreieck;
Switch(xAchse)
??????????????
}
【问题讨论】: