小编Phi*_*Bot的帖子

如何在Raspberry Pi上使用C++将收到的UDP音频数据正确写入ALSA

我有2个Raspberry Pis,其中1个将UDP帧的音频数据传输到另一个Raspberry Pi.收到的UDP数据包各为160字节.传输的Raspberry Pi正在发送8KHz 8位单声道样本.接收Raspberry Pi使用带有QUDPSocket的Qt 5.4.0并尝试使用ALSA播放接收的数据.代码如下.每当字节到达接收Raspberry Pi时触发"readyRead"信号,缓冲区就会写入ALSA.我在接收Pi上的耳机插孔中发出了非常低声和毛躁的声音 - 但它是可识别的.所以它工作但听起来很糟糕.

  1. 对于ALSA,我的配置是否有任何明显的错误?
  2. 我应该如何使用snd_pcm_writei将收到的UDP数据包写入ALSA?

谢谢你的任何建议.

UdpReceiver::UdpReceiver(QObject *parent) : QObject(parent)
{

    // Debug
    qDebug() << "Setting up a UDP Socket...";

    // Create a socket
    m_Socket = new QUdpSocket(this);

    // Bind to the 2616 port
    bool didBind = m_Socket->bind(QHostAddress::Any, 0x2616);
    if ( !didBind ) {
        qDebug() << "Error - could not bind to UDP Port!";
    }
    else {
        qDebug() << "Success binding to port 0x2616!";
    }

    // Get notified that data is incoming to …
Run Code Online (Sandbox Code Playgroud)

c++ linux qt alsa raspberry-pi

7
推荐指数
1
解决办法
1104
查看次数

Chart.js使用X轴时间动态更新图表

我正在使用Chart.js版本2.7.1,并且在输入温度数据时动态更新线形图。

问题在于,这些线永远不会及时通过x轴的中途标记。每次更新时,图表都会自动缩放x轴的右侧(最长时间)以使其更远,因此我的数据永远不会接近图表的右侧。我想要的是使该线接近右侧,并且每次更新时,x轴的未来仅会扩展一小段时间。我该怎么做?谢谢。

这是我配置图表的方式:

var ctx = document.getElementById('tempChart').getContext('2d');
ctx.canvas.width = 320;
ctx.canvas.height = 240;

var chart = new Chart(ctx, {
  type: 'line',
  data: {
      labels: [],
      legend: {
         display: true
      },
      datasets: [{
          fill: false,
          data: [],
          label: 'Hot Temperature',
          backgroundColor: "#FF2D00",
          borderColor: "#FF2D00",
          type: 'line',
          pointRadius: 1,
          lineTension: 2,
          borderWidth: 2
      },
      {
          fill: false,
          data: [],
          label: 'Cold Temperature',
          backgroundColor: "#0027FF",
          borderColor: "#0027FF",
          type: 'line',
          pointRadius: 1,
          lineTension: 2,
          borderWidth: 2
      }]
  },
  options: {
    animation: false,
    responsive: true, …
Run Code Online (Sandbox Code Playgroud)

javascript chart.js chart.js2

7
推荐指数
1
解决办法
765
查看次数

适用于NVIDIA Jetson Nano的PyTorch的Yocto Warrior Bitbake食谱

我正在尝试为Python 3 PyTorch创建一个简单的Yocto Python食谱。目标是Yocto从meta-tegra层为NVIDIA Jetson Nano制作的SD卡映像。没有这些配方,我就可以成功地从meta-tegra编译并引导映像。

NVIDIA本身已经编译并发布了“ .whl” Python软件包,可以在以下位置找到它们:https ://devtalk.nvidia.com/default/topic/1048776/official-tensorflow-for-jetson-nano-/

使用他们的构建说明,我尝试编写一个Bitbake配方来安装PyTorch,如下所示:

SUMMARY = "Facebook PyTorch AI"
DESCRIPTION = "Facebook PyTorch AI"
HOMEPAGE = "https://pytorch.org/"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://LICENSE;md5=acf4d595f99e159bf31797aa872aef57"

inherit pypi
inherit setuptools3

#BBCLASSEXTEND = "native nativesdk"

DEPENDS += "python3-pytest-runner-native python3-pyyaml-native cmake-native"

do_configure_prepend() {
  USE_NCCL=0
  USE_DISTRIBUTED=0
  TORCH_CUDA_ARCH_LIST="5.3;6.2;7.2"
}

do_compile_prepend() {
  USE_NCCL=0
  USE_DISTRIBUTED=0
  TORCH_CUDA_ARCH_LIST="5.3;6.2;7.2"
}

SRC_URI = "gitsm://github.com/pytorch/pytorch.git;protocol=https"
SRCREV = "a3346e100e7f4e7ec90f18b7befcccc47d5a1c82"

S = "${WORKDIR}/git"
Run Code Online (Sandbox Code Playgroud)

问题是我遇到了以下错误。我认为这与我的环境变量未被获取有关,因为错误包括“ -DUSE_CUDA = False”,但是当我查看bitbake环境(bitbake -e)时,它似乎在那里。

这是错误:

**NOTE: Executing SetScene Tasks
NOTE: Executing RunQueue Tasks
ERROR: …
Run Code Online (Sandbox Code Playgroud)

python linux python-3.x bitbake yocto

7
推荐指数
1
解决办法
278
查看次数

如何在Ubuntu上从JPEG或其他图像创建YUV422帧

我想从任何图像在Ubuntu上创建一个示例YUV422帧,这样我就可以为了学习而编写YUV422到RGB888的功能.我真的希望能够使用可信任的工具来创建示例并转换回jpeg.

我尝试过ImageMagick,但显然做错了:

convert -size 640x480 -depth 24 test.jpg -colorspace YUV -size 640x480 -depth 16 -sampling-factor 4:2:2 tmp422.yuv
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

convert -colorspace YUV -size 640x480 -depth 16 -sampling-factor 4:2:2 tmp422.yuv -size 640x480 -depth 24 -colorspace RGB test2.jpg
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

我还在Ubuntu上安装了mpegtools包,以便使用jpeg2yuv:

>> jpeg2yuv -f 1 test.jpg
   INFO: [jpeg2yuv] Reading jpeg filenames from stdin.
   INFO: [jpeg2yuv] Parsing & checking input files.

**ERROR: [jpeg2yuv] System error while opening: "": No such file or directory
Run Code Online (Sandbox Code Playgroud)

显然,别的东西是错的.请问有人可以说明如何实现这一目标吗?谢谢 -

ubuntu rgb image-processing yuv imagemagick-convert

6
推荐指数
1
解决办法
9453
查看次数

Qt通过HTTP流式传输大型文件并刷新到eMMC Flash

我在一个内存受限的嵌入式Linux设备上通过HTTP将大文件(1Gb)传输到Qt中的服务器.当我第一次收到标题时,我确定在文件系统上写入数据的位置,创建一个指向该位置的QFile指针,然后打开要附加的文件.每次新数据到达套接字时,都会在服务器中调用"accumulate"函数.从那个累积函数我想通过write()将数据直接传输到文件.你可以在下面看到我的累积功能.

我的问题是这样做时的内存使用 - 我的内存不足.我不应该能够刷新()和fsync()累积的每次迭代,而不必担心RAM使用?我做错了什么,我该如何解决这个问题?谢谢 -

我在累积函数之前打开一次文件:

// Open the file
filePointerToWriteTo->open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Unbuffered)
Run Code Online (Sandbox Code Playgroud)

这是累积函数的一部分:

// Extract the QFile pointer from the QVariant
QFile *filePointerToWriteTo = (QFile *)(containerForPointer->pointer).value<void *>();

qDebug() << "APPENDING bytes: " << data.length();

// Write to the file and sync
filePointerToWriteTo->write(data);
filePointerToWriteTo->waitForBytesWritten(-1);
filePointerToWriteTo->flush(); // Flush
fsync(filePointerToWriteTo->handle()); // Make sure bytes are written to disk
Run Code Online (Sandbox Code Playgroud)

编辑:

我检测了我的代码和'waitForBytesWritten(-1)'调用总是返回'false'.文档说这应该等到数据写入设备.

另外,如果我只取消注释'write(data)'行,那么我的空闲内存永远不会减少.会发生什么事?"写"如何消耗这么多内存?

编辑:

现在我正在做以下事情.我没有内存耗尽,但我的可用内存降至2Mb并在那里盘旋直到整个文件被传输.此时,内存被释放.如果我在中间杀死传输,内核似乎保持内存,因为它保持大约2Mb可用,直到我重新启动进程并尝试写入同一个文件.我仍然认为我应该能够在每次迭代时使用和刷新内存:

// Extract the QFile pointer from the QVariant
QFile *filePointerToWriteTo = (QFile *)(containerForPointer->pointer).value<void *>();

int numberOfBytesWritten = …
Run Code Online (Sandbox Code Playgroud)

streaming qt http qtembedded qfile

6
推荐指数
1
解决办法
828
查看次数

Amazon AWS Cognito和Python Boto3建立AWS连接并将文件上传到Bucket

我正在尝试使用AWS cognito服务来验证和上传文件.我已经提供了我的regionType,identityPool,AWS账户ID和UnAuthRole.我也知道生产和开发桶的名称.

我想我正在设置AWS Access Key和AWS Secret Key ...我想使用cognito进行身份验证并使用结果来允许我进行存储桶列表以及稍后的文件上传.

我究竟做错了什么?如何使用cognito id建立S3连接?

这是我的代码和产生的错误:

#!/usr/bin/python

import boto3
import boto
#boto.set_stream_logger('foo')
import json
client = boto3.client('cognito-identity','us-east-1')
resp =  client.get_id(AccountId='<ACCNTID>',IdentityPoolId='<IDPOOLID>')
print "\nIdentity ID: %s"%(resp['IdentityId'])
print "\nRequest ID: %s"%(resp['ResponseMetadata']['RequestId'])
resp = client.get_open_id_token(IdentityId=resp['IdentityId'])
token = resp['Token']
print "\nToken: %s"%(token)
print "\nIdentity ID: %s"%(resp['IdentityId'])
resp = client.get_credentials_for_identity(IdentityId=resp['IdentityId'])
secretKey = resp['Credentials']['SecretKey']
accessKey = resp['Credentials']['AccessKeyId']
print "\nSecretKey: %s"%(secretKey)
print "\nAccessKey ID: %s"%(accessKey)
print resp
conn = boto.connect_s3(aws_access_key_id=accessKey,aws_secret_access_key=secretKey,debug=0)
print "\nConnection: %s"%(conn)
for bucket in conn.get_all_buckets():
    print bucket.name
Run Code Online (Sandbox Code Playgroud)

错误:

   Traceback (most recent …
Run Code Online (Sandbox Code Playgroud)

python amazon-s3 boto amazon-web-services boto3

6
推荐指数
1
解决办法
1万
查看次数

使用OpenCV HoG SVM预测2.4中的代码在3.4.1中不起作用

我正在复制我的一些旧代码,用于OpenCV 2.4.1的工作,并允许我为OpenCV的SVM训练我自己的HoG(方向梯度直方图)描述符.我现在将这个旧的工作代码移植到OpenCV 3.4.1,我注意到相当多的API已经改变.

我已将其移植并编译并运行,但是当我尝试通过调用"预测"来测试我的训练周期以确定我的测试图像中是否有人时,我的应用程序死于"SIGFPE:算术异常".

我已经确保用于预测器的CV :: Mat匹配存储在我的"trainedSVM.xml"数据中的Mats的形状.可能有什么不对?我怎样才能解决这个问题?谢谢.

我尝试像这样测试我训练过的数据集:

// Load trained SVM xml data
    Ptr<SVM> svm = SVM::create();
    svm->load("trainedSVM.xml");

    //count variable
    int nnn = 0, ppp = 0;

    // Get a directory iterator
    QDir dir;
    if ( type == 1 ) {
        qDebug() << "\n\nTesting images in Test Directory!";
        dir = QDir("test");
    }
    else if ( type == 2 ) {
        qDebug() << "\n\nTesting images in Pos Directory!";
        dir = QDir("pos");
    }
    else {
        qDebug() << "\n\nTesting images in Neg …
Run Code Online (Sandbox Code Playgroud)

c++ linux opencv opencv3.0 opencv3.1

6
推荐指数
0
解决办法
224
查看次数

如何在PyPy中安装/使用cx_Oracle

我似乎无法在Google或SO上找到任何关于让cx_Oracle与PyPy一起工作的信息.有人可以告诉我是否有可能,如果是的话,我怎么能做到这一点?

python cx-oracle pypy

5
推荐指数
1
解决办法
1277
查看次数

Windows上的QtCreator使用CodeSourcery工具链交叉编译Linux ARM

我在Windows 7机器上安装了Qt Creator,目标是OMAP3嵌入式Linux主板.我下载了目标工具链,Sourcery-G ++ Lite for Windows,还在我的Windows机器上安装了MinGW(http://www.mingw.org/).在QT Creator中,我将CodeSourcery工具链添加为"手动"工具链,如下图所示.然后,我尝试使用此工具链构建演示Qt App'analogclock',为'analogclock'演示应用程序编辑'Projects'下的'Build Settings'.但是在第2张图片中显示的Build Settings下没有工具链.

如何使用构建选项中的Code Sourcery工具链从Qt Creator构建此演示应用程序或任何Qt应用程序?我绝对必须使用Windows来完成这个(不能使用Linux VM ...).

我相信它可能与为目标构建Qt库有关,但我不确定这是否属实或如何在Windows上执行此操作.非常感谢您的帮助和见解.

Qt Creator CodeSourcery工具链

Qt Creator构建设置

编辑:新信息 - 需要帮助配置Qt Creator:

我已经使用CodeSourcery工具链来构建Qt 4.8库而没有错误,我在http://c2143.blogspot.com/?view=classic之后在/ lib目录中有.so文件.现在我试图挂钩CodeSourcery编译器并将Qt 4.8构建到Qt Creator,这样我就可以为目标板构建一个示例应用程序.

我阅读了以下文章:http : //doc.qt.nokia.com/qtcreator-2.4/creator-project-qmake.html http://doc.qt.nokia.com/qtcreator-2.4/creator-tool-chains .html 描述如何将Qt版本的新工具链添加到Qt Creator.请参阅附件中有关我如何配置Qt Creator的图片.我正在使用Qt Creator 2.4.1.

Qt版本 工具链 Buildsettings

我收到错误,但下面没有太多信息粘贴......对此或我的配置有什么想法?

09:51:07: Running build steps for project analogclock...
09:51:07: Configuration unchanged, skipping qmake step.
09:51:07: Starting: "C:\QtSDK\mingw\bin\mingw32-make.exe" 
arm-none-linux-gnueabi-g++ -c -pipe -march=armv7-a -mtune=cortex-a8 -mthumb -mfpu=neon -mfloat-abi=softfp -Wa,-mimplicit-it=thumb -O2 -Wall -W -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED -I"..\qt-4.8-src\include\QtCore" -I"..\qt-4.8-src\include\QtNetwork" -I"..\qt-4.8-src\include\QtGui" -I"..\qt-4.8-src\include" -I"." …
Run Code Online (Sandbox Code Playgroud)

qt cross-compiling qt-creator toolchain linux-toolchain

5
推荐指数
1
解决办法
1万
查看次数

Qt将负十六进制字符串转换为有符号整数

我正在读取i2c设备的寄存器,返回值的范围是-32768到32768,有符号整数.以下是一个例子:

# i2cget -y 3 0x0b 0x0a w
0xfec7
Run Code Online (Sandbox Code Playgroud)

在Qt中,我得到这个值(0xfec7)并希望将它作为有符号整数显示在QLabel中.变量stringListSplit [0]是一个值为'0xfec7'的QString.

// Now update the label
int milAmps = stringListSplit[0].toInt(0,16); // tried qint32
qDebug() << milAmps;
Run Code Online (Sandbox Code Playgroud)

问题是无论我尝试什么,我总是得到无符号整数,所以对于这个例子,我得到的65223超过了指定的最大返回值.我需要将十六进制值转换为有符号整数,因此我需要将十六进制值视为用2s补码表示.我没有在QString文档中看到一个简单的方法.我怎样才能在Qt中实现这一目标?

注意:

QString :: toShort返回0:

// Now update the label
short milAmps = stringListSplit[0].toShort(0,16);
qDebug() << "My new result: " << milAmps;
Run Code Online (Sandbox Code Playgroud)

对于stringListSplit [0]的输入等于'0xfebe',我得到-322的输出,使用由Keith回答的C风格的转换,如下所示:

// Now update the label
int milAmps = stringListSplit[0].toInt(0,16);
qDebug() << "My new result: " << (int16_t)milAmps;
Run Code Online (Sandbox Code Playgroud)

c++ qt hex signed

5
推荐指数
1
解决办法
3086
查看次数