python - 无论如何将videoCapture(0)(来自python文件)放在C#用户界面中
问题描述
我正在做关于人脸识别的项目。我正在研究在 Visual Studio 2019 中使用 C# 创建用户界面
我想知道如何将实时视频输出从videoCapture.py
C# 用户界面
这是代码videoCapture.py
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
while(True):
# Capture frame-by-frame
ret, frame = cap.read()
# Our operations on the frame come here
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Display the resulting frame
cv2.imshow('frame',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
这是 UI 的命名空间代码
namespace DropDownMenu
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
var menuReceptionist = new List<SubItem>();
menuReceptionist.Add(new SubItem("Profiles", new UserControlAdd()));
var item0 = new ItemMenu("Receptionist", menuReceptionist, PackIconKind.ViewDashboard);
var menuAdmin = new List<SubItem>();
menuAdmin.Add(new SubItem("Admins Profile", new UserControlAdmins()));
menuAdmin.Add(new SubItem("Add Admin", new UserControlAdd()));
var item1 = new ItemMenu("Administrations", menuAdmin, PackIconKind.FaceProfile);
var menuPreprocess = new List<SubItem>();
menuPreprocess.Add(new SubItem("New Data", new UserControlAdmins()));
var item2 = new ItemMenu("Data PreProcessing", menuPreprocess, PackIconKind.Schedule);
Menu.Children.Add(new UserControlMenuItem(item0, this));
Menu.Children.Add(new UserControlMenuItem(item1, this));
Menu.Children.Add(new UserControlMenuItem(item2, this));
}
internal void SwitchScreen(object sender)
{
var screen = ((UserControl)sender);
if(screen!=null)
{
StackPanelMain.Children.Clear();
StackPanelMain.Children.Add(screen);
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
Window1 win1 = new Window1();
win1.Show();
this.Close();
}
}
}
如果我做错了什么,我提前道歉。这是我第一次在 Stackoverflow 上发帖
解决方案
您需要从 c# 运行您的 python 脚本,这可以通过几种方法来完成。这里有一篇文章解释了这个过程:
推荐阅读
- ruby-on-rails - rails 6 错误消息不适用于登录/注册模式
- reactjs - 如何实现 SASS 以与原始 webpack 做出反应?
- java - 使用 JSCH 将文件从一个远程服务器发送到另一个使用 JSCH 的服务器
- python - 尝试在 Python 中关闭 Tkinter 窗口时发生 TypeError
- php - 将美分转换为美元并返回浮点值
- python-3.x - 打印总和大于或等于目标的最小子数组
- python - 如何解释热图(或一般)上的负相关?
- javascript - 如何在使用 sweetalert2 显示下一个警报之前等待操作完成
- ios - UITabBar 文本未与横向模式下的图标正确对齐
- flutter - 用户如何在颤抖中互相发送付款