我正在用python写一个OpenCV程序,在某些时候我有类似的东西
import cv2
import numpy as np
...
img = cv2.imread("myImage.jpg")
# do stuff with image here
Run Code Online (Sandbox Code Playgroud)
问题是我必须在继续之前检测图像文件是否正确读取.如果无法打开图像则cv2.imread
返回False
,所以我想做的事情如下:
if (img):
#continue doing stuff
Run Code Online (Sandbox Code Playgroud)
如果图像未打开(例如,如果文件不存在)img
等于None
(如预期的那样),会发生什么.然而,当imread
工作,条件,休息:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Run Code Online (Sandbox Code Playgroud)
即返回的numpy.ndarray
不能用作布尔值.问题似乎是imread
如果成功则返回numpy.ndarray,False
否则返回(布尔值).
到目前为止,我的解决方案涉及使用type
返回值,如下所示:
if (type(img) is np.ndarray):
#do stuff with image
Run Code Online (Sandbox Code Playgroud)
但我想知道:是否有更好的解决方案,更接近初始检查if(img): #do stuff
?
我有一个函数,当触发时,成功显示一个DialogFragment与以下代码
DialogFragment
DialogFragment dialog;
View dialogView;
Context activityContext;
...
dialog = new DialogFragment(){
@Override public Dialog onCreateDialog(Bundle savedInstanceState) {
dialogView = getActivity().getLayoutInflater().inflate(R.layout.customView, null);
...
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setView(dialogView);
return builder.create();
}
};
dialog.show(activityContext.getSupportFragmentManager() , "MyDialog");
Run Code Online (Sandbox Code Playgroud)
问题是,在我添加一个带有以下代码的系统警报窗口后,DialogFragment不再显示,但是如果我传递到另一个应用程序,当我的应用程序最小化时,我可以看到DialogFragment,同时它减小了它的大小
系统警报窗口
WindowManager mWindowManager;
WindowManager.LayoutParams params;
...
mWindowManager = (WindowManager)activityContext.getSystemService(Context.WINDOW_SERVICE);
params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT
}
params.gravity = Gravity.CENTER_VERTICAL | Gravity.RIGHT;
addView(((LayoutInflater)activityContext.getSystemService("layout_inflater")).inflate(R.layout.floatingBotton, null));
Run Code Online (Sandbox Code Playgroud)
那么......为什么我不能在顶部看到我的对话框(据我所知,对话框正在显示)为什么它只在显示系统警报窗口时发生
我已尝试使用系统警报窗口的其他标志,但我遇到了与我尝试过的问题相同的问题
android android-dialogfragment dialogfragment system-alert-window
我只搜索几个字段,但我希望能够将整个文档存储在ES中,以免其他DB(MySQL)查询.
我试图加入index: no
,store: no
在整个映射对象/属性,但我仍然不知道,如果字段被索引并添加不必要的开销.
假设我有书,每个人都有作者.我想只按书名搜索,但我希望能够检索整个文档.
这个可以吗:
mappings:
properties:
title:
type: string
index: analyzed
author:
type: object
index: no
store: no
properties:
first_name:
type: string
last_name:
type: string
Run Code Online (Sandbox Code Playgroud)
或者我应该这样做:
mappings:
properties:
title:
type: string
index: analyzed
author:
type: object
properties:
first_name:
index: no
store: no
type: string
last_name:
index: no
store: no
type: string
Run Code Online (Sandbox Code Playgroud)
或者我可能完全错了?关于什么的nested
性质不应被编入索引?
我有一个类使用了几个模板化的策略.它Dish
在以下示例中调用.我将许多这些Dish
es 存储在一个vector
(使用指向简单基类的指针)中,但是我想提取并使用它们.但我不知道他们的确切类型.
这是代码; 它有点长,但很简单:
#include <iostream>
#include <vector>
struct DishBase {
int id;
DishBase(int i) : id(i) {}
};
std::ostream& operator<<(std::ostream& out, const DishBase& d) {
out << d.id;
return out;
}
// Policy-based class:
template<class Appetizer, class Main, class Dessert>
class Dish : public DishBase {
Appetizer appetizer_;
Main main_;
Dessert dessert_;
public:
Dish(int id) : DishBase(id) {}
const Appetizer& get_appetizer() { return appetizer_; }
const Main& get_main() { return main_; }
const …
Run Code Online (Sandbox Code Playgroud) 我正在尝试找出做以下事情的最佳方法:
(A)使用Web浏览器(例如Chrome / Chromium)在客户端PC中捕获视频帧。
(B)将它们发送到运行C ++处理算法(例如,基于OpenCV的突变松鼠检测例程)的服务器计算机。
(C)将处理结果发送回客户端PC的浏览器以显示它们(实时效果不错,但总的延迟当然是可以预期的)。
到目前为止,我发现WebRTC非常适合(A)(getUserMedia()等。)以及从理论上讲(B)。将数据发送到C ++服务器时会出现我的问题。我一直在寻找WebRTC的基础知识(包括P2P通信示例和Native C ++ API文档),但是对于如何开始构建服务器以及从浏览器发送数据,我仍然一无所知。虽然我对Javascript的经验很少,但是我已经在类似的场景中工作(带有webSocket的Javascript Client <-> C ++ Server),但是我应该更容易实现webRTC解决方案。
我是否适合在这种情况下使用webRTC?我想念什么吗?是否有任何教程或示例涵盖了我错过的场景?
我想使用OpenCV检测一个对象,它与场景中的其他元素明显不同,因为它是灰色的.这很好,因为我可以用R == G == B进行测试,并且它允许独立于亮度,但是逐像素地进行测试很慢.
有没有更快的方法来检测灰色的东西?也许有一个OpenCV方法可以进行R == G == B测试... cv2.inRange
颜色阈值处理,它不是我想要的.
我正在尝试创建一个模板向导,其中项目名称(在"New Project .."对话框中捕获)是向下的,并用于在C++中生成不同的东西(命名空间,库名,等等......),所以生成的名称不能包含破折号,以数字开头等.
例如,在wizard.xml中,变量LIBRARYNAME
是从用户输入生成的,但是它%ProjectName:l%
默认采用downcased :
<fieldpagetitle>Project Configuration</fieldpagetitle>
<fields>
<!-- Library name -->
<field mandatory="true" name="LIBRARYNAME">
<fieldcontrol class="QLineEdit" validator='^[^-]+$'
defaulttext="%ProjectName:l%" />
<fielddescription>Name for created library (all lowercase)</fielddescription>
</field>
Run Code Online (Sandbox Code Playgroud)
使用正则validator = '^[^-]+$'
表达式,我可以阻止用户在变量中引入破折号(' - ')但我无法阻止它们在设置%ProjectName%
变量时执行相同操作.
是否有任何可能的方法来跳过%ProjectName%
向导使用的不需要的符号和/或其他变量?例如"defaulttext"
,在xml中生成时.
到目前为止,我尝试使用不同的类似javascript的东西,但没有任何效果,模板向导上的文档太简单了,它们没有涵盖这些内容.
现在我的选择是删除表单中的默认文本,但这很糟糕!我想做很酷的事情,比如从项目名称生成命名空间名称.
我遇到了类似于此的声明(根据NDA更改了名称):
class Foo
{
int bar;
public:
explicit Foo (Fu *parent = NULL);
private:
void somefunc (String);
signals: // ??? what does this do ???
void windowClosed();
};
Run Code Online (Sandbox Code Playgroud)
这是由g ++ 4.4.7(从大约2012年)成功编译的.此外,vim将其识别为类似的关键字,public
并private
以棕色突出显示.(DIS)similiarly,Vim使用绿色突出关键字namespace
,class
,void
,int
,double
,float
,char
,unsigned
,等.
在#1代码格式化并没有突出signals
像它上面public
和private
!
事实证明谷歌很难(很多噪音),但我没有发现任何提及它,甚至没有提到它.我还查看了g ++文档的增强功能部分.
这个代码库很大(2300万行),古老(〜1998),并且有明显的重音.例如,相同的类定义private slots:
在两个成员函数之前具有类访问权限.所以有可能会有一些#define
混淆或欺骗,但我找不到它grep
.g ++可能已被更改,但其--version
输出并不表示修改.
从昨天开始,我一直在尝试使用 JAVA 在终端 (MAC) 上执行命令,但无论我做什么都不工作。
我有以下 2 个命令要执行并在 JAVA 中获取输出
source activate abc_env
python example.py
Run Code Online (Sandbox Code Playgroud)
到目前为止,我已经尝试了以下方法而没有任何输出
String[] command = new String[] { "source activate abc_env", "python example.py"};
String result = executeCommands(command);
Run Code Online (Sandbox Code Playgroud)
这是我的 executeCommands 方法
private static String executeCommands(String[] command) {
StringBuffer output = new StringBuffer();
Process p;
try {
for(int i=0; i< command.length;i++)
{
p = Runtime.getRuntime().exec(command[i]);
p.waitFor();
BufferedReader reader =
new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
while ((line = reader.readLine())!= null) {
output.append(line + "\n");
}
System.out.println("Error output: …
Run Code Online (Sandbox Code Playgroud) 我需要代码来查找图像的熵.
for(int i=0;i<grey_image.rows;i++)
{
for(int j=1;j<grey_image.cols;j++)
{
//cout<<i<<" "<<j<<" "<<(int)grey_image.at<uchar>(i,j)<<endl;
int a=(int)grey_image.at<uchar>(i,j);
int b=(int)grey_image.at<uchar>(i,j-1);
int x=a-b;
if(x<0)
x=0-x;
probability_array[x]++;
//grey_image.at<uchar>(i,j) = 255;
}
}
//calculating probability
int n=rows*cols;
for(int i=0;i<256;i++)
{
probability_array[i]/=n;
//cout<<probability_array[i]<<endl;
}
// galeleo team formula
float entropy=0;
for(int i=0;i<256;i++)
{
if (probability_array[i]>0)
{
float x=probability_array[i]*log(probability_array[i]);
entropy+=x;
}
}
return 0-entropy;
Run Code Online (Sandbox Code Playgroud)
实际上我正在使用它来转储可编程相机来测量熵.现在我想在windows系统中使用它.我得到一个灰色图像的熵为零.请帮帮我.我哪里做错了.