我需要尝试这些代码,因为在 5 秒后运行这段代码然后会跳转到另一个函数。我如何结合使用线程?
private Mat get_template(CascadeClassifier clasificator, Rect area,int size){
Mat template = new Mat();
Mat mROI = mGray.submat(area);
MatOfRect eyes = new MatOfRect();
Point iris = new Point();
Rect eye_template = new Rect();
clasificator.detectMultiScale(mROI, eyes, 1.15, 2,Objdetect.CASCADE_FIND_BIGGEST_OBJECT|Objdetect.CASCADE_SCALE_IMAGE, new Size(30,30),new Size());
Rect[] eyesArray = eyes.toArray();
for (int i = 0; i < eyesArray.length; i++){
Rect e = eyesArray[i];
e.x = area.x + e.x;
e.y = area.y + e.y;
Rect eye_only_rectangle = new Rect((int)e.tl().x,(int)( e.tl().y + e.height*0.4),(int)e.width,(int)(e.height*0.6));
// reduce ROI
mROI = mGray.submat(eye_only_rectangle);
Mat vyrez = mRgba.submat(eye_only_rectangle);
// find the darkness point
Core.MinMaxLocResult mmG = Core.minMaxLoc(mROI);
// draw point to visualise pupil
Core.circle(vyrez, mmG.minLoc,2, new Scalar(255, 255, 255, 255),2);
iris.x = mmG.minLoc.x + eye_only_rectangle.x;
iris.y = mmG.minLoc.y + eye_only_rectangle.y;
eye_template = new Rect((int)iris.x-size/2,(int)iris.y-size/2 ,size,size);
Core.rectangle(mRgba,eye_template.tl(),eye_template.br(),new Scalar(255, 0, 0, 255), 2);
// copy area to template
template = (mGray.submat(eye_template)).clone();
return template;
}
return template;
}
资源来自:http://romanhosek.cz/android-eye-detection-and-tracking-with-opencv/
正在使用这些代码吗?
try{
//print something here
Thread.sleep(3000); //sleep for 3 seconds
//print something else here
}
catch(InterruptedException e){
System.out.println("got interrupted!");
}
我该如何组合?其实这部分代码是检测眼睛,现在我要做的是检测眼睛5秒后会跳转到另一个功能代码。
我可以输入什么代码来与它们结合?如果您有任何想法,需要帮助回答。
谢谢
最佳答案
- 运行第一个方法
2.5 秒后在 UI 线程中执行某些操作:
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
// Stop 1st one
// run 2nd
}
}, 5000);
关于java - 我如何在 5 秒内运行代码然后跳转到 Android studio Java 中的其他代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41200726/