• 概述

FFmpeg是一套可以用来记录、转换数字音频、视频,并能将其转化为流的开源计算机程序。采用LGPL或GPL许可证。它提供了录制、转换以及流化音视频的完整解决方案。官方提供了Windows、Mac OS X等多个平台的二进制包,可惜没有Android版本库。

  • 编译阶段

1、下载最新版本Ffmpeg源码(目前官方发布的最新版本为1.1),下载地址:https://ffmpeg.org/releases/ffmpeg-4.1.tar.bz2

2、我编译使用的NDK版本android-ndk-r16b, 下载地址:https://dl.google.com/android/repository/android-ndk-r16b-windows-x86_64.zip

3、交叉编译工具MinGW,下载地址: http://www.mingw.org/

安装时其实先装的是个下载管理器,到选择安装选项的时候要选上msys-base和mingw32-gcc-ada两项

4、为了满足Android对库文件的调用格式,需要修改一个configure文件【文件位置:ffmpeg-4.1/configure】,修改格式如下:

将原来的内容

SLIBNAME_WITH_MAJOR=’$(SLIBNAME).$(LIBMAJOR)’

LIB_INSTALL_EXTRA_CMD=’$$(RANLIB) “$(LIBDIR)/$(LIBNAME)”‘

SLIB_INSTALL_NAME=’$(SLIBNAME_WITH_VERSION)’

SLIB_INSTALL_LINKS=’$(SLIBNAME_WITH_MAJOR) $(SLIBNAME)’

修改为如下

SLIBNAME_WITH_MAJOR=’$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)’

LIB_INSTALL_EXTRA_CMD=’$$(RANLIB) “$(LIBDIR)/$(LIBNAME)”‘

SLIB_INSTALL_NAME=’$(SLIBNAME_WITH_MAJOR)’

SLIB_INSTALL_LINKS=’$(SLIBNAME)’

总共四行

5、最重要的是编写下面的脚本

#!/bin/bash

export TMPDIR=F:/SVNMgr/projects/glasses/ffmegp_android_compile/ffmpeg-4.1/ffmpegtemp

#F:/demo/ffmpeg-3.0/ffmpegtemp #设置编译中临时文件目录,不然会报错 unable to create temporary file

 

# NDK的路径,根据实际安装位置设置

#NDK=D:/adt-bundle-windows-x86_64-20131030/sdk/ndk-bundle

NDK=E:/Java/android-ndk-r16b

 

# 编译针对的平台,这里选择最低支持android-14, arm架构,生成的so库是放在libs/armeabi文件夹下的,若针对x86架构,要选择arch-x86

PLATFORM=$NDK/platforms/android-14/arch-arm

 

# 工具链的路径,arm-linux-androideabi-4.9与上面设置的PLATFORM对应,4.9为工具的版本号

TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64

 

function build_one

{

./configure \

–prefix=$PREFIX \

–enable-shared \

–disable-static \

–disable-doc \

–disable-ffmpeg \

–disable-ffplay \

–disable-ffprobe \

–disable-ffserver \

–disable-avdevice \

–disable-doc \

–disable-symver \

–cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \

–target-os=linux \

–arch=arm \

–enable-cross-compile \

–sysroot=$PLATFORM \

–extra-cflags=”-I$PLATFORM/usr/include” \

 

$ADDITIONAL_CONFIGURE_FLAG

sed -i ” ‘s/HAVE_LRINT 0/HAVE_LRINT 1/g’ config.h

sed -i ” ‘s/HAVE_LRINTF 0/HAVE_LRINTF 1/g’ config.h

sed -i ” ‘s/HAVE_ROUND 0/HAVE_ROUND 1/g’ config.h

sed -i ” ‘s/HAVE_ROUNDF 0/HAVE_ROUNDF 1/g’ config.h

sed -i ” ‘s/HAVE_TRUNC 0/HAVE_TRUNC 1/g’ config.h

sed -i ” ‘s/HAVE_TRUNCF 0/HAVE_TRUNCF 1/g’ config.h

sed -i ” ‘s/HAVE_CBRT 0/HAVE_CBRT 1/g’ config.h

sed -i ” ‘s/HAVE_RINT 0/HAVE_RINT 1/g’ config.h

make clean

make -j4

make install

}

 

# arm v7vfp

CPU=armv7-a

OPTIMIZE_CFLAGS=”-mfloat-abi=softfp -mfpu=vfp -marm -march=$CPU ”

PREFIX=./android/$CPU-vfp

ADDITIONAL_CONFIGURE_FLAG=

build_one

不同的Ffmpeg版本和NDK版本,脚本是有差异的,最新Ffmpeg版本,网上的脚本基本编译不过的。

  1. 大概等待10分钟左右,中间或许出现一些小错误,修复一下就好,要是报大面积错误,或者是编译配置不正确。

7、生成结果

最终生成的结果如下:

 

 

 

 

 

 

 

 

 

 

 

一、注册云平台账号,地址为:https://open.ys7.com/

账号分为个人版和企业版本,最主要的差别是:并发数和网络带宽限制

开发和测试阶段 可以使用个人版,无须费用;正式产品发布的时候根据需要购买企业版即可。

二、下载萤石SDK,地址为:https://open.ys7.com/mobile/download.html 

SDK支持多个平台,Windows 、Mac和Linux   本文主要讲述Windows相关开发要点

三、包含相关的头文件

主要文件如下:

OpenNetStreamDefine.h      OpenNetStreamError.h      OpenNetStreamInterFace.h

INS_ErrorCode.h      backward/OpenNetStreamBackwardWarning.h      backward/OpenNetStreamInterfaceBackward.h

四、包含相关的库文件

主要库文件如下:

AnalyzeData.lib  libeay32.lib  OpenNetStream.lib StunClientLib.lib

AudioIntercom.lib libGetHDSign.lib opensslwrap.lib      SystemTransform.lib

hlog.lib libPPVClient2.lib paho-mqtt3c.lib TTSClient.lib      hpr.lib MidPage.lib PlayCtrl.lib pthreadVC2.lib udt.lib

libCASClient.lib miniupnpc.lib PushClient.lib      libcurl.lib NetStream.lib ssleay32.lib streamclient_lib.lib

五、开发流程

1、配置好账号信息:AppKey、Secret【进入注册的账号页面查看】

2、配置平台地址和授权地址:

<authaddress>https://openauth.ys7.com</authaddress>

<platformadress>https://open.ys7.com</platformadress>

3、初始化萤石SDK

示例代码如下:

CDataStoreMgr* pDS  = CDataStoreMgr::GetDataStoreMgrInstance();

CGeneralSettings* pGeneralSettings = pDS->GetGeneralSettings();

CConstSettings* pConstSettings = pDS->GetConstSettings();

QString strAuthAdd = pConstSettings->m_strAuthAddress;

QString strPlatformAdd = pConstSettings->m_strPlatformAddress;

QString strAppKey = pConstSettings->m_strAppKey;

OpenNetStream* pONS = OpenNetStream::getInstance();

int nRet = pONS->initLibrary(strAuthAdd, strPlatformAdd, strAppKey);
//初始化视频窗口

for each (CVideoWnd* var in m_vectVideoWnds)

{

var->InitLib();

}

注:窗口是初始化主要是为每个窗口分配一个Session,建立一个视频链接的

4、访问AccessToken配置,【注册进入的账号页面有个测试token】,在代码中需要动态获取,最好在过期前一天(有效期7天)跟萤石云平台或者一次更新,

特别留意:频繁请求可能导致封账号

请求token示例代码如下:

QString strRet(“”);

QDateTime dtCur = QDateTime::currentDateTime();

qint64 nCurr = dtCur.toMSecsSinceEpoch();

CConstSettings* pCS = CDataStoreMgr::GetDataStoreMgrInstance()->GetConstSettings();

CGeneralSettings* pGS = CDataStoreMgr::GetDataStoreMgrInstance()->GetGeneralSettings();

qint64 nExpire = pGS->m_nTokenExpireTime;

if (nExpire <= nCurr) //重新请求Token

{

QUrl url(“https://open.ys7.com/api/lapp/token/get”);

QNetworkRequest requestURL(url);

QByteArray paramsByte;

QString strParams = QString(“appKey=%1&appSecret=%2”).arg(pGS->m_strAppKey).arg(pGS->m_strSecret);

paramsByte = strParams.toUtf8(); QNetworkReply* pReplay = m_networkMgr.post(requestURL,paramsByte);

}

else

{

strRet = pGS->m_strToken;

}

return strRet;

5、以上步骤都成功了,就可以进行视频控制

一、倍福TWinCAT ADS简述

在Beckhoff TwinCAT 系统中,各个软件模块(如TwinCAT PLC、TwinCAT NC、Windows 应用程序等)及硬件系统CX、BX、BC 系列控制器中包含TwinCAT 信息路由器。因此各个ADS 设备之间都能够交换数据和信息。

二、TWinCat ADS 设备标识

每台TwinCAT ADS 设备都有各自不同的AdsAmsNetId 和AdsPort(端口号), AdsAmsNetId 是TCP/IP 地址的扩展,默认为在IP基础上增加.1.1,也可以进行修改。

 ADS 客户端(ADS Client)应用程序的AdsPort 则是可变的。不同ADS 设备的AdsPort 如下图所示:

ADS 设备  AdsPort
PC 控制器中的PLC Run-time system 1 801
Run-time system 2 811
Run-time system 3 821
Run-time system 4 831
自定义任务( Additional Task ) Additional Task 1 301
Additional Task 2 302
BC、BX 控制器中的PLC 800
NC 500

 

三、TwinCat ADS通讯方式(同步和异步两种方式)

  • 异步方式(Asynchronous)

ADS 客户端向ADS 服务器发送ADS 请求,同时客户端继续自己的工作。ADS 服务器处理请求后,把响应以Call-back 函数方式发给客户端。

优点:不会造成系统堵塞

缺点:不能确保每次请求都有返回

  • 同步方式(Synchronous)

ADS 客户端向ADS 服务器发送ADS 请求,在通讯过程中客户端程序停止执行,直到获得ADS 服务器返回的响应

优点:能即时返回结果

缺点:如果通讯故障会造成系统堵塞

同步方式(Synchronous)通讯分为两种,即读操作和写操作,针对于读和写操作又分别分为两种方式,即按变量名进行读写和按照地址进行读写。

1、变量名方式

在TwinCAT PLC程序中每个变量都有一个句柄(Handle)。在对变量进行操作之前,首先我们要通过相关路径得到变量的句柄,然后进行读写操作,操作完毕后对句柄进行释放。

2、地址方式

在TwinCAT PLC中一个变量的地址由两部分组成,即GroupIndex和OffsetIndex, GroupIndex为该变量所在的寄存器类型,为一常量; OffsetIndex为该变量在寄存器中得地址偏移量,为一变量。

GroupIndex值 描述
0x00004020 M寄存器(用%M声明)
0x00004021 MX寄存器(用MX声明)
0x0000F020 I寄存器(用%I声明)
0x0000F021 IX寄存器(用IX声明)
0x0000F030 Q寄存器(用%Q声明)
0x0000F031 QX寄存器(用QX声明)
0x0000F003 取变量的句柄
0x0000F005 通过变量句柄访问变量值
0x0000F006 释放句柄

 1.对于MX,IX,QX寄存器的偏移地址的单位是“位”,而不是字节,计算地址需要注意

2.M寄存器偏移地址最大值为0x0000FFFF,而MX,I,IX,Q,QX偏移地址最大值为0xFFFFFFFF。

3.上表后三个主要用于C++语言,其他高级语言已经封装成专有方法,不需直接调用

四、按变量名和按变量地址进行操作的比较

1.变量名方式

  优点:

  • 无需知道变量的具体地址;
  • 可以省略计算地址的工作;
  • 可对过程变量进行操作;

    缺点:

  • 因为要抓放句柄(10ms),和地址方式比较通讯速度慢
  • 对BC、BX系列不能进行操作
  1. 地址方式

   优点:

  • 直接对地址进行操作,省去抓放句柄时间,通讯速度快;
  • 无需知道变量的具体路径;
  • 可以操作BC、BX系列控制器

     缺点:

           A、使用中需考虑不同变量的偏移地址,容易出错。

五、TwinCAT 通讯高级语言接口

  • 开放、简单、 灵活、 文档齐全

 

六、TwinCAT 通讯高级语言组件

为方便各种计算机高级语言及其环境使用ADS通讯,Beckhoff TwinCAT提供相如下组件:

  • ADS .NET Component

适用.NET平台,VB.NET,C#等

  • ADS-OCX (ActiveX COM控件)

适用于Visual Basic, Visual C++, Delphi等.

  • ADS-DLL

适用于Visual C++等.

  • ADS-Script-DLL

适用于 VBScript, Jscript等脚本,创建B/S架构的应用.

  • JAVA DLL

适用于JAVA语言。

  • “PlcSystem.lib” PLC 库

ADS设备可以通过据此和其他ADS设备以及Windows进行通讯

七、TwinCAT 通讯高级语言组件获取

ADS组件库集成在TwinCAT软件中,安装任何版本的TwinCAT软件都包含ADS通讯组件,如果用户希望在没有安装TwinCAT软件的计算机适用ADS通讯组件可以安装Supplement中的TwinCAT_ADS_Communication_Library此为免费产品。

八、Qt C++ VS2015 工程设置示例

A、需要的相关文件

需要包含的头文件: TcAdsAPI.h 和 TcAdsDef.h

需要包含的Lib文件: TcAdsDll.lib

程序运行目录需要包含库文件: TcAdsDll.dll

B、设置方式

我们在工程目录下面新建一个目录,命名为: ads_include 【包含文件TcAdsAPI.h 和 TcAdsDef.h】

加入工程方法:工程属性 -> C/C++ -> 常规 附加包含目录 中添加 ads_include即可

我们在工程目录下面新建一个目录,命名为: libs 【包含文件TcAdsDll.lib】

加入工程方法:工程属性-> 链接器 -> 常规 附加库目录 中添加 libs即可

工程属性-> 链接器->输入 附加依赖项 中添加TcAdsDll.lib即可

同时需要把TcAdsDll.dll 库放置于程序的执行目录中。

九、推荐的Qt C++ 软件结构设计图【已经产品化实践过】

十、其他问题

1、注意字节对齐,尽量统一使用4倍或者8倍字节数,也能大大提高内存访问命中率

2、注意通讯高效性,尽量使用地址访问方式

3、注意线程同步,保持主界面线程操作流程

问题描述
最近因有个工业控制项目的需要,有一幅65000X18000的bmp图需要去绘制;但是按照目前Qt 提供的类QPixmap 或者 QImage,都没有办法直接完成这项工作的。通过阅读Qt源码我们发现,Qt支持绘制的最大区域为32767X 32767;

为了突破Qt这个限制,解决这个技术瓶颈问题,我们设计出一种切片思想解决方案,具体如下:

1、对一幅超大的图片进行切片,使其范围在 32767 X 32767 范围内。
2、绘制工作在切片上操作执行
3、把绘制好的切片图像再重新写会原始超大图中,完美实现大图绘制工作。

示例代码如下

QImage image(65000,18000,QImage::Format_Mono);
1、获取切片区域
QRect rcSlice(100,1000,40000,10000);
QImage imageSlice = image.copy(rcSlice)
2、绘制操作
QPainter painter(&imageSlice);
….
….
3、切换写回原始大图中
int x = 0;
int y = 0;
int w = m_rcLastCpy.width();
int h = m_rcLastCpy.height();
int pixels_to_copy = w;
int lines_to_copy = h;
bool byteAligned = !(pixels_to_copy & 7);
if (byteAligned)
{
const uchar *src = image.bits();
uchar *dest = m_pImage->bits() + ((m_rcLastCpy.x() * m_pImage->depth()) >> 3) + m_rcLastCpy.y() * m_pImage->depth()*m_pImage->bytesPerLine();
const int bytes_to_copy = (pixels_to_copy * image.depth()) >> 3;
for (int i = 0; i < lines_to_copy; ++i) { memcpy(dest, src, bytes_to_copy); src += image.bytesPerLine(); dest += m_pImage->bytesPerLine();
}
}
else
{
const uchar *src = image.bits();
uchar *dest = m_pImage->bits() + m_rcLastCpy.y() * m_pImage->bytesPerLine();
for (int i = 0; i < lines_to_copy; ++i) {
for (int j = 0; j < pixels_to_copy; ++j) { if (src[(x + j) >> 3] & (0x80 >> ((x + j) & 7)))
dest[(j) >> 3] |= (0x80 >> ((j) & 7));
else
dest[(j) >> 3] &= ~(0x80 >> ((j) & 7));
}
src += image.bytesPerLine();
dest += m_pImage->bytesPerLine();
}
}

至此,完美的解决了超大图绘制的工作。

 

视频眼镜解决方案(视频设备、移动端、PC端和服务端)【视频、语音】

 

 

 

 

 

 

 

 

 

 

 

 

 

证券行情和交易软件

 

视频监控系统(萤石SDK二次开发

 

 

工业控制类项目(倍福系统开发)

 

上海联通项目

 

OMAPL138(ARM9+C674X)项目

考试系统

 

企业现金宝

 

云笔记

 

券商行情和交易软件

 

网络连接管理

 

更多技术产品支持更新,敬请期待………

眼下最热门的技术,绝对是人工智能。

人工智能的底层模型是“神经网络”(neural network)。许多复杂的应用(比如模式识别、自动控制)和高级模型(比如深度学习)都基于它。学习人工智能,一定是从它开始。

什么是神经网络呢?网上似乎缺乏通俗的解释。

前两天,我读到 Michael Nielsen 的开源教材《神经网络与深度学习》(Neural Networks and Deep Learning),意外发现里面的解释非常好懂。下面,我就按照这本书,介绍什么是神经网络。

这里我要感谢优达学城的赞助,本文结尾有他们的《前端开发(进阶)》课程的消息,欢迎关注。

一、感知器

历史上,科学家一直希望模拟人的大脑,造出可以思考的机器。人为什么能够思考?科学家发现,原因在于人体的神经网络。

  1. 外部刺激通过神经末梢,转化为电信号,转导到神经细胞(又叫神经元)。
  2. 无数神经元构成神经中枢。
  3. 神经中枢综合各种信号,做出判断。
  4. 人体根据神经中枢的指令,对外部刺激做出反应。

既然思考的基础是神经元,如果能够”人造神经元”(artificial neuron),就能组成人工神经网络,模拟思考。上个世纪六十年代,提出了最早的”人造神经元”模型,叫做“感知器”(perceptron),直到今天还在用。

上图的圆圈就代表一个感知器。它接受多个输入(x1,x2,x3…),产生一个输出(output),好比神经末梢感受各种外部环境的变化,最后产生电信号。

为了简化模型,我们约定每种输入只有两种可能:1 或 0。如果所有输入都是1,表示各种条件都成立,输出就是1;如果所有输入都是0,表示条件都不成立,输出就是0。

二、感知器的例子

下面来看一个例子。城里正在举办一年一度的游戏动漫展览,小明拿不定主意,周末要不要去参观。

他决定考虑三个因素。

  1. 天气:周末是否晴天?
  2. 同伴:能否找到人一起去?
  3. 价格:门票是否可承受?

这就构成一个感知器。上面三个因素就是外部输入,最后的决定就是感知器的输出。如果三个因素都是 Yes(使用1表示),输出就是1(去参观);如果都是 No(使用0表示),输出就是0(不去参观)。

三、权重和阈值

看到这里,你肯定会问:如果某些因素成立,另一些因素不成立,输出是什么?比如,周末是好天气,门票也不贵,但是小明找不到同伴,他还要不要去参观呢?

现实中,各种因素很少具有同等重要性:某些因素是决定性因素,另一些因素是次要因素。因此,可以给这些因素指定权重(weight),代表它们不同的重要性。

  • 天气:权重为8
  • 同伴:权重为4
  • 价格:权重为4

上面的权重表示,天气是决定性因素,同伴和价格都是次要因素。

如果三个因素都为1,它们乘以权重的总和就是 8 + 4 + 4 = 16。如果天气和价格因素为1,同伴因素为0,总和就变为 8 + 0 + 4 = 12。

这时,还需要指定一个阈值(threshold)。如果总和大于阈值,感知器输出1,否则输出0。假定阈值为8,那么 12 > 8,小明决定去参观。阈值的高低代表了意愿的强烈,阈值越低就表示越想去,越高就越不想去。

上面的决策过程,使用数学表达如下。

上面公式中,x表示各种外部因素,w表示对应的权重。

四、决策模型

单个的感知器构成了一个简单的决策模型,已经可以拿来用了。真实世界中,实际的决策模型则要复杂得多,是由多个感知器组成的多层网络。

上图中,底层感知器接收外部输入,做出判断以后,再发出信号,作为上层感知器的输入,直至得到最后的结果。(注意:感知器的输出依然只有一个,但是可以发送给多个目标。)

这张图里,信号都是单向的,即下层感知器的输出总是上层感知器的输入。现实中,有可能发生循环传递,即 A 传给 B,B 传给 C,C 又传给 A,这称为“递归神经网络”(recurrent neural network),本文不涉及。

五、矢量化

为了方便后面的讨论,需要对上面的模型进行一些数学处理。

  • 外部因素 x1x2x3 写成矢量 <x1, x2, x3>,简写为 x
  • 权重 w1w2w3 也写成矢量 (w1, w2, w3),简写为 w
  • 定义运算 w⋅x = ∑ wx,即 w 和 x 的点运算,等于因素与权重的乘积之和
  • 定义 b 等于负的阈值 b = -threshold

感知器模型就变成了下面这样。

六、神经网络的运作过程

一个神经网络的搭建,需要满足三个条件。

  • 输入和输出
  • 权重(w)和阈值(b
  • 多层感知器的结构

也就是说,需要事先画出上面出现的那张图。

其中,最困难的部分就是确定权重(w)和阈值(b)。目前为止,这两个值都是主观给出的,但现实中很难估计它们的值,必需有一种方法,可以找出答案。

这种方法就是试错法。其他参数都不变,w(或b)的微小变动,记作Δw(或Δb),然后观察输出有什么变化。不断重复这个过程,直至得到对应最精确输出的那组wb,就是我们要的值。这个过程称为模型的训练。

因此,神经网络的运作过程如下。

  1. 确定输入和输出
  2. 找到一种或多种算法,可以从输入得到输出
  3. 找到一组已知答案的数据集,用来训练模型,估算wb
  4. 一旦新的数据产生,输入模型,就可以得到结果,同时对wb进行校正

可以看到,整个过程需要海量计算。所以,神经网络直到最近这几年才有实用价值,而且一般的 CPU 还不行,要使用专门为机器学习定制的 GPU 来计算。

七、神经网络的例子

下面通过车牌自动识别的例子,来解释神经网络。

所谓”车牌自动识别”,就是高速公路的探头拍下车牌照片,计算机识别出照片里的数字。

这个例子里面,车牌照片就是输入,车牌号码就是输出,照片的清晰度可以设置权重(w)。然后,找到一种或多种图像比对算法,作为感知器。算法的得到结果是一个概率,比如75%的概率可以确定是数字1。这就需要设置一个阈值(b)(比如85%的可信度),低于这个门槛结果就无效。

一组已经识别好的车牌照片,作为训练集数据,输入模型。不断调整各种参数,直至找到正确率最高的参数组合。以后拿到新照片,就可以直接给出结果了。

八、输出的连续性

上面的模型有一个问题没有解决,按照假设,输出只有两种结果:0和1。但是,模型要求wb的微小变化,会引发输出的变化。如果只输出01,未免也太不敏感了,无法保证训练的正确性,因此必须将”输出”改造成一个连续性函数。

这就需要进行一点简单的数学改造。

首先,将感知器的计算结果wx + b记为z


z = wx + b

然后,计算下面的式子,将结果记为σ(z)


σ(z) = 1 / (1 + e^(-z))

这是因为如果z趋向正无穷z → +∞(表示感知器强烈匹配),那么σ(z) → 1;如果z趋向负无穷z → -∞(表示感知器强烈不匹配),那么σ(z) → 0。也就是说,只要使用σ(z)当作输出结果,那么输出就会变成一个连续性函数。

原来的输出曲线是下面这样。

现在变成了这样。

实际上,还可以证明Δσ满足下面的公式。

ΔσΔwΔb之间是线性关系,变化率是偏导数。这就有利于精确推算出wb的值了。

 

Pycharm 官网地址:https://www.jetbrains.com

有两个版本:

社区版本和商业版本

商业版本收费是:首年收费199美金

开始学习阶段,社区版本足够了。

首先通过官网下载对应的pycharm版本

然后配置tensor flow相关信息,具体如下(引用自stack overflow):

This is a working solution for me, first create a virtualenv from Pycharm and then install tensorflow there:

  1. In Pycharm, Preferences -> Project interpreter -> Create VirtualEnv -> give the virtualenv a name and location of your choice, and select “inherit global site-packages” option -> OK. create virtualenv
  2. In command line, install tensorflow in the virtualenv location you created in Step 1. For the above case, the location is ~/tensorflow_pycharm, therefore, run command virtualenv --system-site-packages ~/tensorflow_pycharm
  3. In Pycharm, select the created project interpreter, and select the tensorflow package, double click to install the package.
  4. If Step 3 is successful, set run configuration, and try run a sample program. run configsample program

 

主要针对 系统 MacOS X 10.11 (El Capitan) or 更新

Installing TensorFlow on macOS

This guide explains how to install TensorFlow on macOS.

Determine how to install TensorFlow

You must pick the mechanism by which you install TensorFlow. The supported choices are as follows:

  • virtualenv
  • “native” pip
  • Docker
  • installing from sources, which is documented in a separate guide.

We recommend the virtualenv installation. Virtualenv is a virtual Python environment isolated from other Python development, incapable of interfering with or being affected by other Python programs on the same machine. During the virtualenv installation process, you will install not only TensorFlow but also all the packages that TensorFlow requires. (This is actually pretty easy.) To start working with TensorFlow, you simply need to “activate” the virtual environment. All in all, virtualenv provides a safe and reliable mechanism for installing and running TensorFlow.

Native pip installs TensorFlow directly on your system without going through any container or virtual environment system. Since a native pip installation is not walled-off, the pip installation might interfere with or be influenced by other Python-based installations on your system. Furthermore, you might need to disable System Integrity Protection (SIP) in order to install through native pip. However, if you understand SIP, pip, and your Python environment, a native pip installation is relatively easy to perform.

Docker completely isolates the TensorFlow installation from pre-existing packages on your machine. The Docker container contains TensorFlow and all its dependencies. Note that the Docker image can be quite large (hundreds of MBs). You might choose the Docker installation if you are incorporating TensorFlow into a larger application architecture that already uses Docker.

In Anaconda, you may use conda to create a virtual environment. However, within Anaconda, we recommend installing TensorFlow with the pip install command, not with the conda install command.

NOTE: The conda package is community supported, not officially supported. That is, the TensorFlow team neither tests nor maintains the conda package. Use that package at your own risk.

Installing with virtualenv

Take the following steps to install TensorFlow with Virtualenv:

  1. Start a terminal (a shell). You’ll perform all subsequent steps in this shell.
  2. Install pip and virtualenv by issuing the following commands:
     $ sudo easy_install pip
     $ pip install --upgrade virtualenv
  3. Create a virtualenv environment by issuing a command of one of the following formats:
     $ virtualenv --system-site-packages targetDirectory # for Python 2.7
     $ virtualenv --system-site-packages -p python3 targetDirectory # for Python 3.n
    

    where targetDirectory identifies the top of the virtualenv tree. Our instructions assume that targetDirectory is ~/tensorflow, but you may choose any directory.

  4. Activate the virtualenv environment by issuing one of the following commands:
    $ source ~/tensorflow/bin/activate      # If using bash, sh, ksh, or zsh
    $ source ~/tensorflow/bin/activate.csh  # If using csh or tcsh

    The preceding source command should change your prompt to the following:

     (tensorflow)$
  5. Ensure pip ≥8.1 is installed:
     (tensorflow)$ easy_install -U pip
  6. Issue one of the following commands to install TensorFlow and all the packages that TensorFlow requires into the active Virtualenv environment:
     (tensorflow)$ pip install --upgrade tensorflow      # for Python 2.7
     (tensorflow)$ pip3 install --upgrade tensorflow     # for Python 3.n
    
  7. Optional. If Step 6 failed (typically because you invoked a pip version lower than 8.1), install TensorFlow in the active virtualenv environment by issuing a command of the following format:
     $ pip install --upgrade tfBinaryURL   # Python 2.7
     $ pip3 install --upgrade tfBinaryURL  # Python 3.n

    where tfBinaryURL identifies the URL of the TensorFlow Python package. The appropriate value of tfBinaryURLdepends on the operating system and Python version. Find the appropriate value for tfBinaryURL for your systemhere. For example, if you are installing TensorFlow for macOS, Python 2.7, the command to install TensorFlow in the active Virtualenv is as follows:

     $ pip3 install --upgrade \
     https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.4.0-py2-none-any.whl

If you encounter installation problems, see Common Installation Problems.

Next Steps

After installing TensorFlow, validate your installation to confirm that the installation worked properly.

Note that you must activate the virtualenv environment each time you use TensorFlow in a new shell. If the virtualenv environment is not currently active (that is, the prompt is not (tensorflow), invoke one of the following commands:

$ source ~/tensorflow/bin/activate      # bash, sh, ksh, or zsh
$ source ~/tensorflow/bin/activate.csh  # csh or tcsh

Your prompt will transform to the following to indicate that your tensorflow environment is active:

 (tensorflow)$

When the virtualenv environment is active, you may run TensorFlow programs from this shell.

When you are done using TensorFlow, you may deactivate the environment by issuing the following command:

 (tensorflow)$ deactivate

The prompt will revert back to your default prompt (as defined by PS1).

Uninstalling TensorFlow

If you want to uninstall TensorFlow, simply remove the tree you created. For example:

 $ rm -r ~/tensorflow

Installing with native pip

We have uploaded the TensorFlow binaries to PyPI. Therefore, you can install TensorFlow through pip.

The REQUIRED_PACKAGES section of setup.py lists the packages that pip will install or upgrade.

Prerequisite: Python

In order to install TensorFlow, your system must contain one of the following Python versions:

  • Python 2.7
  • Python 3.3+

If your system does not already have one of the preceding Python versions, install it now.

When installing Python, you might need to disable System Integrity Protection (SIP) to permit any entity other than Mac App Store to install software.

Prerequisite: pip

Pip installs and manages software packages written in Python. If you intend to install with native pip, then one of the following flavors of pip must be installed on your system:

  • pip, for Python 2.7
  • pip3, for Python 3.n.

pip or pip3 was probably installed on your system when you installed Python. To determine whether pip or pip3 is actually installed on your system, issue one of the following commands:

$ pip -V  # for Python 2.7
$ pip3 -V # for Python 3.n

We strongly recommend pip or pip3 version 8.1 or higher in order to install TensorFlow. If pip or pip3 8.1 or later is not installed, issue the following commands to install or upgrade:

$ sudo easy_install --upgrade pip
$ sudo easy_install --upgrade six

Install TensorFlow

Assuming the prerequisite software is installed on your Mac, take the following steps:

  1. Install TensorFlow by invoking one of the following commands:
     $ pip install tensorflow      # Python 2.7; CPU support
     $ pip3 install tensorflow     # Python 3.n; CPU support

    If the preceding command runs to completion, you should now validate your installation.

    
    
  2. (Optional.) If Step 1 failed, install the latest version of TensorFlow by issuing a command of the following format:
     $ sudo pip  install --upgrade tfBinaryURL   # Python 2.7
     $ sudo pip3 install --upgrade tfBinaryURL   # Python 3.n

    where tfBinaryURL identifies the URL of the TensorFlow Python package. The appropriate value of tfBinaryURLdepends on the operating system and Python version. Find the appropriate value for tfBinaryURL here. For example, if you are installing TensorFlow for Mac OS and Python 2.7 issue the following command:

     $ sudo pip3 install --upgrade \
     https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.4.0-py2-none-any.whl

    If the preceding command fails, see installation problems.

Next Steps

After installing TensorFlow, validate your installation to confirm that the installation worked properly.

Uninstalling TensorFlow

To uninstall TensorFlow, issue one of following commands:

$ pip uninstall tensorflow
$ pip3 uninstall tensorflow

Installing with Docker

Follow these steps to install TensorFlow through Docker.

  1. Install Docker on your machine as described in the Docker documentation.
  2. Launch a Docker container that contains one of the TensorFlow binary images.

The remainder of this section explains how to launch a Docker container.

To launch a Docker container that holds the TensorFlow binary image, enter a command of the following format:

 $ docker run -it -p hostPort:containerPort TensorFlowImage

where:

  • -p hostPort:containerPort is optional. If you’d like to run TensorFlow programs from the shell, omit this option. If you’d like to run TensorFlow programs from Jupyter notebook, set both hostPort and containerPort to 8888. If you’d like to run TensorBoard inside the container, add a second -p flag, setting both hostPort and containerPort to 6006.
  • TensorFlowImage is required. It identifies the Docker container. You must specify one of the following values:
    • gcr.io/tensorflow/tensorflow: TensorFlow binary image.
    • gcr.io/tensorflow/tensorflow:latest-devel: TensorFlow Binary image plus source code.

gcr.io is the Google Container Registry. Note that some TensorFlow images are also available at dockerhub.

For example, the following command launches a TensorFlow CPU binary image in a Docker container from which you can run TensorFlow programs in a shell:

$ docker run -it gcr.io/tensorflow/tensorflow bash

The following command also launches a TensorFlow CPU binary image in a Docker container. However, in this Docker container, you can run TensorFlow programs in a Jupyter notebook:

$ docker run -it -p 8888:8888 gcr.io/tensorflow/tensorflow

Docker will download the TensorFlow binary image the first time you launch it.

Next Steps

You should now validate your installation.

Installing with Anaconda

The Anaconda installation is community supported, not officially supported.

Take the following steps to install TensorFlow in an Anaconda environment:

  1. Follow the instructions on the Anaconda download site to download and install Anaconda.
  2. Create a conda environment named tensorflow by invoking the following command:
    $ conda create -n tensorflow python=2.7 # or python=3.3, etc.
  3. Activate the conda environment by issuing the following command:
    $ source activate tensorflow
     (tensorflow)$  # Your prompt should change
  4. Issue a command of the following format to install TensorFlow inside your conda environment:
    (tensorflow)$ pip install --ignore-installed --upgrade TF_PYTHON_URL

    where TF_PYTHON_URL is the URL of the TensorFlow Python package. For example, the following command installs the CPU-only version of TensorFlow for Python 2.7:

     (tensorflow)$ pip install --ignore-installed --upgrade \
     https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.4.0-py2-none-any.whl

Validate your installation

To validate your TensorFlow installation, do the following:

  1. Ensure that your environment is prepared to run TensorFlow programs.
  2. Run a short TensorFlow program.

Prepare your environment

If you installed on native pip, virtualenv, or Anaconda, then do the following:

  1. Start a terminal.
  2. If you installed with virtualenv or Anaconda, activate your container.
  3. If you installed TensorFlow source code, navigate to any directory except one containing TensorFlow source code.

If you installed through Docker, start a Docker container that runs bash. For example:

$ docker run -it gcr.io/tensorflow/tensorflow bash

Run a short TensorFlow program

Invoke python from your shell as follows:

$ python

Enter the following short program inside the python interactive shell:

# Python
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))

If the system outputs the following, then you are ready to begin writing TensorFlow programs:

Hello, TensorFlow!

If you are new to TensorFlow, see Getting Started with TensorFlow.

If the system outputs an error message instead of a greeting, see Common installation problems.

Common installation problems

We are relying on Stack Overflow to document TensorFlow installation problems and their remedies. The following table contains links to Stack Overflow answers for some common installation problems. If you encounter an error message or other installation problem not listed in the following table, search for it on Stack Overflow. If Stack Overflow doesn’t show the error message, ask a new question about it on Stack Overflow and specify the tensorflow tag.

Stack Overflow Link Error Message
42006320
ImportError: Traceback (most recent call last):
File ".../tensorflow/core/framework/graph_pb2.py", line 6, in 
from google.protobuf import descriptor as _descriptor
ImportError: cannot import name 'descriptor'
33623453
IOError: [Errno 2] No such file or directory:
  '/tmp/pip-o6Tpui-build/setup.py'
35190574
SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify
  failed
42009190
  Installing collected packages: setuptools, protobuf, wheel, numpy, tensorflow
  Found existing installation: setuptools 1.1.6
  Uninstalling setuptools-1.1.6:
  Exception:
  ...
  [Errno 1] Operation not permitted:
  '/tmp/pip-a1DXRT-uninstall/.../lib/python/_markerlib'
33622019
ImportError: No module named copyreg
37810228 During a pip install operation, the system returns:

OSError: [Errno 1] Operation not permitted
33622842 An import tensorflow statement triggers an error such as the following:

Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/local/lib/python2.7/site-packages/tensorflow/__init__.py",
    line 4, in 
    from tensorflow.python import *
    ...
  File "/usr/local/lib/python2.7/site-packages/tensorflow/core/framework/tensor_shape_pb2.py",
    line 22, in 
    serialized_pb=_b('\n,tensorflow/core/framework/tensor_shape.proto\x12\ntensorflow\"d\n\x10TensorShapeProto\x12-\n\x03\x64im\x18\x02
      \x03(\x0b\x32
      .tensorflow.TensorShapeProto.Dim\x1a!\n\x03\x44im\x12\x0c\n\x04size\x18\x01
      \x01(\x03\x12\x0c\n\x04name\x18\x02 \x01(\tb\x06proto3')
  TypeError: __init__() got an unexpected keyword argument 'syntax'
42075397 pip install command triggers the following error:

...
You have not agreed to the Xcode license agreements, please run
'xcodebuild -license' (for user-level acceptance) or
'sudo xcodebuild -license' (for system-wide acceptance) from within a
Terminal window to review and agree to the Xcode license agreements.
...
  File "numpy/core/setup.py", line 653, in get_mathlib_info

    raise RuntimeError("Broken toolchain: cannot link a simple C program")

RuntimeError: Broken toolchain: cannot link a simple C program

The URL of the TensorFlow Python package

A few installation mechanisms require the URL of the TensorFlow Python package. The value you specify depends on three factors:

  • operating system
  • Python version

This section documents the relevant values for Mac OS installations.

Python 2.7

https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.4.0-py2-none-any.whl

Python 3.4, 3.5, or 3.6

https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.4.0-py3-none-any.whl

Protobuf pip package 3.1

You can skip this section unless you are seeing problems related to the protobuf pip package.

NOTE: If your TensorFlow programs are running slowly, you might have a problem related to the protobuf pip package.

The TensorFlow pip package depends on protobuf pip package version 3.1. The protobuf pip package downloaded from PyPI (when invoking pip install protobuf) is a Python-only library containing Python implementations of proto serialization/deserialization that can run 10x-50x slower than the C++ implementation. Protobuf also supports a binary extension for the Python package that contains fast C++ based proto parsing. This extension is not available in the standard Python-only pip package. We have created a custom binary pip package for protobuf that contains the binary extension. To install the custom binary protobuf pip package, invoke one of the following commands:

  • for Python 2.7:
    $ pip install --upgrade \
    https://storage.googleapis.com/tensorflow/mac/cpu/protobuf-3.1.0-cp27-none-macosx_10_11_x86_64.whl
  • for Python 3.n:
    $ pip3 install --upgrade \
    https://storage.googleapis.com/tensorflow/mac/cpu/protobuf-3.1.0-cp35-none-macosx_10_11_x86_64.whl

Installing this protobuf package will overwrite the existing protobuf package. Note that the binary pip package already has support for protobufs larger than 64MB, which should fix errors such as these:

使用Qt开发完Mac PC版本的应用程序,如何提交苹果的Mac App Stoe 供用户下载使用呢?接下来我们以Qt 5.5.1版本详细介绍发布过程。

步骤:

1、确保代码在Release模式下编译通过,使用XCode或者QtCreator都可以的.
qt的pro工程转成xcode project 命令格式:qmake project.pro -spec macx-xcode

2、编译成功之后,需要处理app中可执行文件以及库的依赖关系,目的使应用程序在非开发环境可以正常运行

有两种方法可以处理:
A、自己使用系统工具install_name_tool 手动处理,这个工作量非常大,而且容易出错
B、使用Qt 自带的工具 macdeployqt, 命令格式:macdeployqt Application.app -verbose=3

查看依赖关系是否正确命令格式:otool -L yourapp.app/Contents/MacOS/yourapp

3、上面两步完成之后,根据App Store 的上线指南,需要对APP进行代码签名,需要注意的签名只是可执行文件和类可执行文件
A、准备好苹果的发布证书(需要开发证书和安装证书),
对包的签名格式如下:
codesign –entitlements ./entitlements.plist –force –verify –verbose –sign ‘3rd Party Mac Developer Application: 公司信息 (XXXXXX2)’ YourApp.app/Contents/Frameworks/QtDBus.framework/Versions/5/QtDBus

对所有的相关库都需要按照上面的模式签名,是所有的。

B、签名完成之后,就需要检验签名是否正确
检验命令格式:codesign –verify –deep –verbose=2 YouApp.app/

4、对签名好的App进行打包
打包命令格式:productbuild –component YourApp.app /Applications YourApp.pkg –sign ‘3rd Party Mac Developer Installer: 公司信息 (XXXXXX2)’

注意这地方使用的安装证书。

最终生产一个可以上传到Mac App Store的应用程序包 YourApp.pkg

5、使用苹果提供的Application Loader工具上传pkg文件,等待苹果审核,然后发布。

自此,程序成功发布到Mac APP Store上

欢迎大家体验Mac App Store 上的应用程序: e海通财

QtPdfium 是一个Qt模块,主要用于操作和显示PDF文件。该模块核心功能使用了pdfium工程,它是Google的一个开源项目(BSD);

一、编译安装步骤

1、Mac/Linux代码编译和安装使用

git clone –recursive https://github.com/paulovap/qtpdfium

cd qtpdfium

qmake

make

make install (might need sudo)

2、Windows代码编译和安装使用

下载源代码

修改代码Win宏变量

支持C++11的编译器进入qtpdfium\src\pdfium 执行nmake命令

执行nmake install安装

编译之后生产的文件如下:

模块安装之后的include目录,Bin目录和Lib目录如下:

Demo程序显示的界面如下:

二、用法
QtPdfium 导出两个重要类:QPdfium 和 QPdfiumPage.
1、包含头文件#include <QtPdfium/QtPdfiumDepends>
2、通过PDF文件名称生产QPdfium对象 QPdfium pdfium(strPDFFileName);
3、通过QPdfium生成QPdfiumPage 对象

//获取PDF文件包含的页数
int nPageCn = pPdfium->pageCount();

//获取指定的页
QPdfiumPage pfPage = pPdfium->page(i);
//由QpdfiumPage生成Qimage
QImage pdfImage = pfPage.image();
//….显示等

三、QPDFium优势
最主要是基于BSD许可的,其他类似的库不具备此属性,导致商业会有一些障碍的。

四、引用参考资料
源码:https://github.com/paulovap/qtpdfium

五、源码以及Demo资料:
源码:http://download.csdn.net/download/goodowxy/9981302
Demo: http://download.csdn.net/download/goodowxy/9981299