我在列表中有一组字符串路径,如["x1/x2/x3","x1/x2/x4","x1/x5"].我需要从这个列表中构造一个树状结构,可以迭代得到一个漂亮的打印树.像这样
x1
/ \
x5 x2
/ \
x3 x4
Run Code Online (Sandbox Code Playgroud)
有什么想法/建议吗?我相信通过处理字符串列表可以首先攻击问题EDIT:选择的正确答案是优雅的实现,其他建议也很好.
目前我这样做:
DaoMaster.dropAllTables(getDb(), true);
DaoMaster.createAllTables(getDb(), true);
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试将实体添加到数据库时,我收到崩溃日志,说这个表不存在
Edit1:我知道发生这种情况是因为数据库被锁定而且还没有创建表.所以我正在解决这个问题 - 如何知道这些表是否被锁定在grrenDao/Sqlite中?
我正在尝试创建一个服务,即使在用户从正在运行的进程菜单中关闭应用程序(通过将进程移出屏幕)之后,也会为我执行后台作业.
我尝试做的是通过声明它在不同的过程中创建服务:
<service
android:name=".service.Service"
android:enabled="true"
android:icon="@drawable/ic_launcher"
android:process=":my_process" >
</service>
Run Code Online (Sandbox Code Playgroud)
而onStartCommand()是:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return START_STICKY;
}
Run Code Online (Sandbox Code Playgroud) 我想知道是否有人使用ARCore SDK实时识别设备前面的垂直平面.
通过使用线方程定义墙来设法获得不错的结果:
z = Multiplier * x + Constant (For every y)
Run Code Online (Sandbox Code Playgroud)
通过"for y y"评论我的意思是我忽略了y轴(从房间的2d映射看上面的墙),以便计算定义墙的线.
乘数是点之间的旋转:
let angleDeg = Float((360 - angle + 360) % 360) * Float.pi / 180.0;
Run Code Online (Sandbox Code Playgroud)
所有计算是:
let angle: Int = Int((atan2(pointA.z - pointB.z, pointA.x - pointB.x) * 180) / Float.pi) % 360
yRotation = Float((360 - angle + 360) % 360) * Float.pi / 180.0
if pointA.x == pointB.x {
multiplier = Float.infinity
} else {
multiplier = (pointA.z - pointB.z) / (pointA.x - …Run Code Online (Sandbox Code Playgroud) 我正在尝试决定选择哪个库来创建可以过滤视频的应用,例如美化或清晰度.
在我搜索期间,我遇到了两个候选人:OpenCv和FFmpeg,我找到了一个仅适用于FFmpeg的完整框架(所以+1为此).
我无法找到两者之间的完全比较,所以如果有人尝试过它们并且可以发布答案,那将非常有帮助.
编辑:
另一个候选人是Android的Marvin框架(Java项目) - https://code.google.com/p/android-image-filtering/
我遇到一个奇怪的问题:getActivity()方法总是在片段内返回null.我在onAttach()和onCreateView()完成运行后调用它.
这个片段存在于包含片段堆栈的FragmentActivity()中,我向其添加片段的方式是:
(此代码是从Fragment Activity()的onCreate()调用的)
SmartFragment fragment;
fragment = (SmartFragment) Fragment.instantiate(this,
fragmentClassName, params);
mStackOfFragments.add(fragment);
FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
trans.add(R.id.tabcontent, fragment);
trans.addToBackStack(null);
trans.commitAllowingStateLoss();
Run Code Online (Sandbox Code Playgroud)
我希望它足够清楚
编辑1:
对getActivity()的调用:
protected OnDoneListener nDoneListener = new OnDoneListener() {
@Override
public void OnDone(final int counter, final String name) {
if (getActivity() != null)
((TabActivity) getActivity()).RunOnUiThread(new Runnable() {
Run Code Online (Sandbox Code Playgroud)
......
这个回调是从另一个类调用的.
编辑2:
class MemoryManager()
{
private OnDoneListener nDoneListener;
public void setOnDoneListener(OnDoneListener onDoneListener)
{
this.onDoneListner = onDoneListener;
}
public void updateUiOnRequestFinish()
{
onDoneListener.onDone();
}
}
Run Code Online (Sandbox Code Playgroud)
MemoryManaget本身从另一个回调调用updateUiOnRequestFinish()
编辑3:
FragmentManager日志是:
04-08 …Run Code Online (Sandbox Code Playgroud) 我已经看过一些关于如何编译和使用FFmpeg for Android的文章.
不幸的是,没有他们,或我发现的其他人帮助我.在这两个示例中,创建了build_android.sh并配置FFmpeg的配置文件并调用make.每当我运行脚本时,我都会收到以下错误:
c:\android\development\android-ndk-r9\sources\ffmpeg>sh build_android.sh
c:/android/development/android-ndk-r9/toolchains/arm-linux-androideabi-4.8/prebu
ilt/windows-x86_64/arm-linux-androideabi/bin/bin/arm-linux-androideabi-gcc is un
able to create an executable file.
C compiler test failed.
If you think configure made a mistake, make sure you are using the latest
version from Git. If the latest version fails, report the problem to the
ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.
Include the log file "config.log" produced by configure as this will help
solving the problem.
Makefile:2: config.mak: No such file …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用MediaCodec从视频中检索所有帧以进行图像处理,我正在尝试渲染视频并从outBuffers捕获帧但我无法从接收到的字节中启动位图实例.
我试图将它渲染到曲面或没有任何东西(null),因为我注意到当渲染为null时,outBuffers将获取渲染帧的字节.
这是代码:
private static final String SAMPLE = Environment.getExternalStorageDirectory() + "/test_videos/sample2.mp4";
private PlayerThread mPlayer = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SurfaceView sv = new SurfaceView(this);
sv.getHolder().addCallback(this);
setContentView(sv);
}
protected void onDestroy() {
super.onDestroy();
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
if (mPlayer == null) {
mPlayer = new PlayerThread(holder.getSurface());
mPlayer.start();
}
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
if (mPlayer != null) { …Run Code Online (Sandbox Code Playgroud) 我有另一个OpenGL ES驱动程序错误.这次我正在尝试编译以下行:
precision mediump float;
varying highp vec2 textureCoordinate;
void main() {
highp vec4 color = texture2D(input0, textureCoordinate);
vec3 color3 = color.rgb;
vec2 tc = (2.0 * textureCoordinate) - 1.0;
float d = dot(tc, tc);
vec2 lookup = vec2(d, color3.r);
..
..
}
Run Code Online (Sandbox Code Playgroud)
但是我正在接受这条线:
GLES20.glLinkProgram(program);
Run Code Online (Sandbox Code Playgroud)
本机崩溃:"致命信号11(SIGDEV)在0x00000060(代码= 1),线程1231"我猜它发生是因为LG nexus 4使用GPU Adreno,它也在我崩溃,错误代码14在另一个崩溃 - 使用太多宏.
我正在尝试编写一个应用程序来获取视频的所有帧并对其进行操作,我发现在 Android 上提取帧的最佳方法是使用 OpenCv lib。
我在使用 VideoCapture 对象的示例代码中看到,该对象接收视频路径并可以从中抓取帧,所以我编写了以下代码,但 capture.open() 并没有真正打开视频文件,即 capture.isOpen( ) 总是假的。
源代码:
#include <jni.h>
//opencv
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/video/background_segm.hpp>
#include <opencv2/core/mat.hpp>
//C
#include <stdio.h>
#include <string.h>
//C++
#include <iostream>
#include <sstream>
//Android
#include <android/log.h>
//#define LOGI(TAG,INFO) __android_log_print(ANDROID_LOG_INFO,INFO,__VA_ARGS__)
using namespace cv;
extern "C" {
JNIEXPORT void JNICALL Java_com_example_nativeopencvcheck_MainActivity_processVideo(JNIEnv* env,
jobject thsObj,jstring fileName) {
const char * fileNameNative;
jboolean isCopy;
fileNameNative = env->GetStringUTFChars(fileName, &isCopy);
//create the capture object
__android_log_print(ANDROID_LOG_ERROR, "From_Native",
"trying to open file: %s", fileNameNative);
VideoCapture capture(fileNameNative);
capture.open(fileNameNative);
if …Run Code Online (Sandbox Code Playgroud)