我正在尝试使用raspberry pi从USB摄像头捕获图像并使用Django框架流式传输我尝试使用StreamingHttpResponse从Opencv2流式传输帧.但是,它只显示1帧而不替换图像.
如何实时替换图像?
这是我的代码.
from django.shortcuts import render
from django.http import HttpResponse,StreamingHttpResponse
import cv2
import time
class VideoCamera(object):
def __init__(self):
self.video = cv2.VideoCapture(0)
def __del__(self):
self.video.release()
def get_frame(self):
ret,image = self.video.read()
ret,jpeg = cv2.imencode('.jpg',image)
return jpeg.tobytes()
def gen(camera):
while True:
frame = camera.get_frame()
yield(frame)
time.sleep(1)
def index(request):
# response = HttpResponse(gen(VideoCamera())
return StreamingHttpResponse(gen(VideoCamera()),content_type="image/jpeg")
Run Code Online (Sandbox Code Playgroud) 我有一个想要读取StorageFolder VideosLibrary的UWP项目,并在带缩略图的Views中显示mp4文件列表.
使用MVVM ligth工具包,我已经使用xaml设置了这4只苍蝇.Xaml正在使用UWP社区工具箱包装面板.
1)ViewModelLocator.cs
namespace UWP.ViewModels
{
/// <summary>
/// This class contains static reference to all the view models in the
/// application and provides an entry point for the bindings.
/// </summary>
class ViewModelLocator
{
/// <summary>
/// Initializes a new instance of the ViewModelLocator class.
/// </summary>
public ViewModelLocator()
{
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
if (ViewModelBase.IsInDesignModeStatic)
{
// Create design time view services and models
}
else
{
// Create run Time view services and models
} …Run Code Online (Sandbox Code Playgroud) 我希望使用 for 循环修改 CuDNNGRU 输出。但是,由于 tf.GradientTape 图形模式,我似乎无法这样做。如何修改功能 API 中的 CuDNNGRU?我知道通常我们可以使用 tf.keras.backend.* 函数(如 K.backend.batch_dot 等)在功能 API 上执行一些矩阵运算。但是,我必须执行一些复杂的运算,如三重 for 循环或更多等,如果有人知道该怎么做,请帮忙!
.....source code
x = L.Lambda(lambda fm: tf.squeeze(fm, axis=1))(x)
gru_1 = CuDNNGRU(512, return_sequences=True, name='gru1')(x)
gru_1b = CuDNNGRU(512, return_sequences=True, go_backwards=True,name='gru1_b')(x)
for i in gru_1:
.....apply some function to gru_1 outputs
Run Code Online (Sandbox Code Playgroud)
顺便说一句,我目前尝试使用以下代码修改 GRU 输出。
def attention(inputs):
transpose_input = tf.transpose(inputs,perm=[0,2,1])
atten_w = K.backend.batch_dot(inputs,transpose_input)
atten_w = tf.linalg.set_diag(atten_w,tf.zeros(tf.shape(atten_w)[0:-1],dtype=tf.float32))
atten_w = tf.nn.softmax(atten_w,axis=1)
atten_v = tf.py_function(calculate_atten,inp=[inputs,atten_w],Tout=[tf.float32])
atten_v = tf.convert_to_tensor(atten_v)
atten_v.set_shape(self.input_shapex)
def calculate_atten(data,atten_w):
input_vector = data.numpy()
atten_vectors = atten_w.numpy()
all_batch = …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个可聚焦的图像,以便显示移动或调整拇指大小。我知道图像标记不是控件,因此它不可聚焦,这在此图像文档中进行了解释。但是我需要做一些事件来让图像知道是否正在聚焦以改变那些控制拇指的可见性。有人知道如何解决这个问题吗?我在 Canvas 中的控制如下。
<Canvas x:Name="test">
<Grid x:Name="grdTextbox" Canvas.Left="300" Canvas.Top="300" Height="200" Width="200" ManipulationMode="None">
<Thumb x:Name="ThumbMove" Background="Transparent" Height="Auto" Width="Auto" DragDelta="ThumbMove_DragDelta" PointerEntered="ThumbMove_PointerEntered" PointerExited="ThumbMove_PointerExited" Margin="5" Canvas.ZIndex="1" />
<Thumb x:Name="ThumbBottomRight" Background="White" BorderBrush="Black" Height="20" Width="20" HorizontalAlignment="Right" DragDelta="ThumbBottomRight_DragDelta" VerticalAlignment="Bottom" PointerEntered="ThumbSizeNorthwestSoutheast_PointerEntered" PointerExited="ThumbMove_PointerExited"/>
<Thumb x:Name="ThumbBottomLeft" Background="White" BorderBrush="Black" Height="20" Width="20" HorizontalAlignment="Left" DragDelta="ThumbBottomLeft_DragDelta" VerticalAlignment="Bottom" PointerEntered="ThumbSizeNortheastSouthwest_PointerEntered" PointerExited="ThumbMove_PointerExited"/>
<Thumb x:Name="ThumbTopRight" Background="White" BorderBrush="Black" Height="20" Width="20" HorizontalAlignment="Right" DragDelta="ThumbTopRight_DragDelta" VerticalAlignment="Top" PointerExited="ThumbMove_PointerExited" PointerEntered="ThumbSizeNortheastSouthwest_PointerEntered"/>
<Thumb x:Name="ThumbTopLeft" Background="White" BorderBrush="Black" Height="20" Width="20" HorizontalAlignment="Left" DragDelta="ThumbTopLeft_DragDelta" VerticalAlignment="Top" PointerExited="ThumbMove_PointerExited" PointerEntered="ThumbSizeNorthwestSoutheast_PointerEntered"/>
<Image Height="Auto" Width="Auto" Source="Assets/Square150x150Logo.png" Margin="2" Stretch="Uniform" PointerEntered="ThumbMove_PointerEntered" PointerExited="ThumbMove_PointerExited" Tapped="Image_Tapped"/>
</Grid>
</Canvas>
Run Code Online (Sandbox Code Playgroud) python ×2
uwp ×2
asynchronous ×1
c# ×1
canvas ×1
controls ×1
django ×1
django-views ×1
image ×1
keras ×1
mvvm-light ×1
opencv ×1
tensorflow ×1
tf.keras ×1
xaml ×1