我有一个公共房间列表。public override void OnRoomListUpdate(List)
我有一个公共房间列表。
public override void OnRoomListUpdate(List<RoomInfo> roomList)
{
foreach (RoomInfo room in roomList)
{
if (room.RemovedFromList)
{
cachedRoomList.Remove(room);
}
else
{
int index = cachedRoomList.FindIndex(r => r.Name == room.Name);
if (index != -1)
{
cachedRoomList[index] = room;
}
else
{
cachedRoomList.Add(room);
}
}
}
UpdatePublicRoomUI();
}
void UpdatePublicRoomUI()
{
foreach (Transform roomButton in publicRoomContainer)
{
Destroy(roomButton.gameObject);
}
foreach (RoomInfo room in cachedRoomList)
{
CreatePublicRoomButton(room.Name, room.PlayerCount);
}
}
void CreatePublicRoomButton(string roomName, int playerCount)
{
GameObject roomButton = Instantiate(publicRoomButton, publicRoomContainer);
roomButton.SetActive(true);
roomButton.transform.GetChild(0).GetComponent<TextMeshProUGUI>().SetText(roomName);
roomButton.transform.GetChild(1).GetComponent<TextMeshProUGUI>().SetText(playerCount.ToString());
UnityEngine.UI.Button button = roomButton.GetComponent<UnityEngine.UI.Button>();
button.onClick.AddListener(() =>
{
JoinRoom(roomName);
});
}
因此基本上,每个将选项 IsVisible
设置为 true 的房间都会显示在这里。一切正常,直到玩家离开房间然后创建一个房间。无论房间是否公开,它都不会显示在这里。以下是离开房间的代码:
public void QuitToMenu()
{
if (PhotonNetwork.InRoom)
{
PhotonNetwork.LeaveRoom();
PhotonNetwork.LoadLevel("Menu");
}
}
以下是创建和加入房间的功能:
public void CreateRoom(string roomName, bool isPublic)
{
RoomOptions roomOptions = new()
{
IsVisible = isPublic,
IsOpen = true,
MaxPlayers = 10
};
PhotonNetwork.CreateRoom(roomName, roomOptions);
}
public void JoinRoom(string roomName)
{
PhotonNetwork.JoinRoom(roomName);
}
public override void OnJoinedRoom()
{
string nickname = nickname_input.text.Trim();
if (nickname.Length > 0)
{
PlayerPrefs.SetString("Nickname", nickname);
PhotonNetwork.NickName = nickname;
}
PhotonNetwork.LoadLevel("Game");
}
看到它正常工作真是太棒了。提前致谢。
我的目标是能够使用 OpenCV 在 Ubuntu 20.04 上使用 Logitech hd C270 网络摄像头捕获图像,但我遇到了一个我不明白的问题。这是我的程序:import cv2def
我的目标是能够使用 Ubuntu 20.04 上的 Logitech hd C270 网络摄像头捕获图像 OpenCV
,但我遇到了一个我不明白的问题。
这是我的程序:
import cv2
def capture_image(device_path, ouput) :
cap = cv2.VideoCapture(device_path)
if not cap.isOpened():
print("Error open the device")
return
ret, frame = cap.read()
print(ret)
print(frame)
if not ret:
print("Error capture image")
return
cv2.imwrite(ouput, frame)
cap.release
print("imahe capturée")
if __name__ == "__main__":
device_path = "/dev/video0"
ouput = "image.jpg"
capture_image(device_path, ouput) `
当我启动我的程序时, ret
是 False
并且 frame
是 None
.
这是我的操作系统:
Linux nahel-VirtualBox 5.15.0-105-generic
#115~20.04.1-Ubuntu SMP Mon Apr 15 17:33:04 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
nahel@nahel-VirtualBox:/$ v4l2-ctl --list-device
C270 HD WEBCAM (usb-0000:00:06.0-2):
/dev/video0
/dev/video1
nahel@nahel-VirtualBox:/$ v4l2-ctl -V
Format Video Capture:
Width/Height : 640/480
Pixel Format : 'YUYV' (YUYV 4:2:2)
Field : None
Bytes per Line : 1280
Size Image : 614400
Colorspace : sRGB
Transfer Function : Rec. 709
YCbCr/HSV Encoding: ITU-R 601
Quantization : Default (maps to Limited Range)
Flags :
nahel@nahel-VirtualBox:/$ v4l2-ctl --list-formats
ioctl: VIDIOC_ENUM_FMT
Type: Video Capture
[0]: 'YUYV' (YUYV 4:2:2)
[1]: 'MJPG' (Motion-JPEG, compressed)
我在 Windows 上尝试了我的代码并且成功了。
是的,我使用 VirtualBox 和 Visual Studio 代码。
以下是使用 V4L2 获得的信息
nahel@nahel-VirtualBox:/$ v4l2-compliance
v4l2-compliance SHA: not available, 64 bits
Compliance test for uvcvideo device /dev/video0:
Driver Info:
Driver name : uvcvideo
Card type : C270 HD WEBCAM
Bus info : usb-0000:00:06.0-2
Driver version : 5.15.148
Capabilities : 0x84a00001
Video Capture
Metadata Capture
Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x04200001
Video Capture
Streaming
Extended Pix Format
Required ioctls:
test VIDIOC_QUERYCAP: OK
Allow for multiple opens:
test second /dev/video0 open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK
Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported)
test VIDIOC_LOG_STATUS: OK (Not Supported)
Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported)
test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK
test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 1 Audio Inputs: 0 Tuners: 0
Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_ENUMAUDOUT: OK (Not Supported)
test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported)
test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0
Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported)
test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported)
test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported)
test VIDIOC_G/S_EDID: OK (Not Supported)
Control ioctls (Input 0):
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK
test VIDIOC_QUERYCTRL: OK
fail: v4l2-test-controls.cpp(445): s_ctrl returned an error (13)
test VIDIOC_G/S_CTRL: FAIL
fail: v4l2-test-controls.cpp(695): s_ext_ctrls returned an error (13)
test VIDIOC_G/S/TRY_EXT_CTRLS: FAIL
test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK
test VIDIOC_G/S_JPEGCOMP: OK (Not Supported)
Standard Controls: 14 Private Controls: 0
Format ioctls (Input 0):
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK
test VIDIOC_G/S_PARM: OK
test VIDIOC_G_FBUF: OK (Not Supported)
test VIDIOC_G_FMT: OK
test VIDIOC_TRY_FMT: OK
warn: v4l2-test-formats.cpp(976): Could not set fmt2
test VIDIOC_S_FMT: OK
test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported)
test Cropping: OK (Not Supported)
test Composing: OK (Not Supported)
test Scaling: OK (Not Supported)
Codec ioctls (Input 0):
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported)
test VIDIOC_G_ENC_INDEX: OK (Not Supported)
test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)
Buffer ioctls (Input 0):
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK
test VIDIOC_EXPBUF: OK
test Requests: OK (Not Supported)
Total for uvcvideo device /dev/video0: 44, Succeeded: 42, Failed: 2, Warnings: 1