We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello everyone!I ran into a problem with using different mods in processing.I use standard library VIdeo https://processing.org/reference/libraries/video/index.html, to grab video from webcam, and i want to switch video mode at the time of shooting a video, you know, like changes resolutions and fps.Is it real?Also i use Control iP5 to make GUI, and i need to change this in listbox(Control iP5),In which all modes are presented.Really need your help.Thanks in advance.
`` import controlP5.*;
import processing.serial.*;
import processing.video.*;
Serial serial;
String received;
ControlP5 cp5;
Capture cam;
int a;
int cnt = 0;
boolean C = false;
int i=0; ``
`` Textlabel myTextlabelA;
ListBox l;
Textlabel myTextlabelB;
void setup() {
String[] cameras = Capture.list();
cp5 = new ControlP5(this);
size(640, 480);
noStroke();
//String port = Serial.list()[0];
//serial = new Serial(this, port, 9600);
cam = new Capture(this, 320, 240, cameras[1]);
cam.start();
myTextlabelA = cp5.addTextlabel("label")
.setText("water="+a)
.setPosition(400, 40)
.setColorValue(#000000)
.setFont(createFont("Georgia", 20))
;
myTextlabelB = cp5.addTextlabel("label1")
.setText("HC-SR04="+a+"m")
.setPosition(400, 80)
.setColorValue(#000000)
.setFont(createFont("Georgia", 20))
;``
`` l = cp5.addListBox("m")
.setPosition(400, 120)
.setSize(140, 140)
.setItemHeight(24)
.setBarHeight(25)
.setColorBackground(color(#ff8800))
.setColorActive(color(0))
.setColorForeground(color(255, 100, 0))
//.setFont(createFont("Times New Roman",14))
.setColorValue(#000000)
.setOpen(false)
.setWidth(230)
;
l.getCaptionLabel().toUpperCase(true);
l.getCaptionLabel().set("Cameras");
l.getCaptionLabel().setColor(#000000);
l.setHeight(250);
l.getCaptionLabel().setSize(15);
l.getCaptionLabel().setWidth(200);
for (i=0; i<cameras.length; i++) {
l.addItem(cameras[i], "ID="+i);
l.getItem(i).put("color", new CColor().setBackground(0xffff0000).setBackground(0xffff8800));
}
//Описание кнопок
cp5.addButton("Forward")
.setPosition(560, 400)
.updateSize()
;
`` cp5.addButton("stop")
.setPosition(560, 420)
.updateSize()
;
cp5.addButton("Backward")
.setPosition(560, 440)
.updateSize()
;
cp5.addButton("Turn on Lights")
.setPosition(20, 400)
.updateSize()
; ``
cp5.addButton("Turn off Lights")
.setPosition(20, 420)
.updateSize() ``
;
cp5.addButton("Move up")
.setPosition(100, 400)
.updateSize()
;
cp5.addButton("Move Down")
.setPosition(100, 420)
.updateSize()
; ``
`` //Список доступных режимов камеры в консоли
println("Available cameras:");
for (int i = 0; i < cameras.length; i++) {
println(cameras[i], "ID=", i);
}
}
void draw() {
background(255, 204, 0);
//Чтение камеры,если доступно
if (cam.available() == true) {
cam.read();
}
image(cam, 20, 20);
}
//Функции Кнопок
public void controlEvent(ControlEvent theEvent) {
println(theEvent.getController().getName());
println(l.getItem(i));
}
public void Forward() {
serial.write('3');
}
public void stop() {
serial.write('1');
}
public void Backward() {
serial.write('2');
}
//Определение нажатий
public void keyPressed() {
if ( key == CODED ) {
if ( keyCode == RIGHT ) {
a=10;
serial.write('1');
} else if ( keyCode == LEFT ) {
a= 10;
serial.write('2');
} else if ( keyCode == UP ) {
a -= 10;
serial.write('0');
} else if ( keyCode == DOWN ) {
a += 10;
stop();
}
}
} ``
p.s. If it's not difficult for you to express yourself simpler please, because my English is terrible(as you see).
Answers
Please edit your post, select your code and hit ctrl+o to format your code. Make sure there is an empty line above and below your code
Kf
I did it