目錄
前言:v4l-utils簡介
一:查找當前的攝像頭設備
二:查看當前攝像頭支持的v4l2-ctl調試參數
三根據提示設置對應參數,在提示范圍內設置
四:常用調試命令
五:應用內執行命令方法
前言:v4l-utils簡介
v4l-utils工具是由Linuxtv維護的一個V4L2開發套件,它提供一系列V4L2及media framework相關的工具,用來配置V4L2子設備的屬性,測試V4L2設備,并提供如libv4l2.so開發庫等等。
本章主要介紹v4l-utils中的兩個命令行工具:media-ctl和v4l2-ctl。
- media-ctl:用以查看、配置拓撲結構;
- v4l2-ctl:用以配置v4l2 controls,可抓幀,設置vin、isp、sensor參數。
在?Rockchip 發布的?Linux SDK 中,默認已集成了?v4l-utils 包。
一:查找當前的攝像頭設備
grep '' /sys/class/video4linux/video*/name
紅框代表是外接的USB攝像頭
二:查看當前攝像頭支持的v4l2-ctl調試參數
v4l2-ctl -d /dev/video21 --list-ctrls
-
三根據提示設置對應參數,在提示范圍內設置
亮度
v4l2-ctl -d /dev/video21 --set-ctrl 'brightness=64'
效果如下:
四:常用調試命令
亮度
v4l2-ctl -d /dev/video21 --set-ctrl 'brightness=64'
飽和度
v4l2-ctl -d /dev/video21 --set-ctrl 'saturation=100'
對比度
v4l2-ctl -d /dev/video21 --set-ctrl 'contrast=95'
銳度
v4l2-ctl -d /dev/video21 --set-ctrl 'sharpness=7'
五:應用內執行命令方法
Path = "/dev/video21"
????public static boolean upgradeRootPermission(String path) {
????????Process process = null;
????????DataOutputStream os = null;
????????try {
????????????String cmd = "chmod 777 " + path;
????????????process = Runtime.getRuntime().exec("su"); //切換到root帳號
????????????os = new DataOutputStream(process.getOutputStream());
????????????os.writeBytes(cmd + "\n");
????????????os.writeBytes("exit\n");
????????????os.flush();
????????????process.waitFor();
????????} catch (Exception e) {
????????} finally {
????????????try {
????????????????if (os != null) {
????????????????????os.close();
????????????????}
????????????????process.destroy();
????????????} catch (Exception e) {
????????????}
????????}
????????try {
????????????if (process == null) {
????????????????return false;
????????????}
????????????return process.waitFor() == 0;
????????} catch (InterruptedException e) {
????????????e.printStackTrace();
????????}
????????return false;
}
Cmd示例:v4l2-ctl -d /dev/video21 --set-ctrl 'brightness=64'
????public static boolean exeCmdForSu(String command) {
????????Log.d("exeCmdForSu", "command = " + command);
????????boolean result = false;
????????DataOutputStream dataOutputStream = null;
????????BufferedReader errorStream = null;
????????try {
????????????Process process = Runtime.getRuntime().exec("su");
????????????dataOutputStream = new DataOutputStream(process.getOutputStream());
????????????String s = command + "\n";
????????????dataOutputStream.write(s.getBytes(Charset.forName("utf-8")));
????????????dataOutputStream.flush();
????????????dataOutputStream.writeBytes("exit\n");
????????????dataOutputStream.flush();
????????????process.waitFor();
????????????errorStream = new BufferedReader(new InputStreamReader(process.getErrorStream()));
????????????String msg;
????????????String line;
????????????for (msg = ""; (line = errorStream.readLine()) != null; msg = msg + line) {
????????????}
????????????Log.d("exeCmdForSu", "exeCmdForSu msg is " + msg);
????????????if (!msg.contains("Failure")) {
????????????????result = true;
????????????}
????????} catch (Exception var16) {
????????????Exception e = var16;
????????????Log.e("exeCmdForSu", e.getMessage(), e);
????????} finally {
????????????try {
????????????????if (dataOutputStream != null) {
????????????????????dataOutputStream.close();
????????????????}
????????????????if (errorStream != null) {
????????????????????errorStream.close();
????????????????}
????????????} catch (IOException var15) {
????????????????IOException e = var15;
????????????????Log.e("exeCmdForSu", e.getMessage(), e);
????????????}
????????}
????????return result;
????}