I have a picture that contains 2 icons at the bottom of the picture i'm already croping the picture to get only the buttom and comparing it with the icon picture opencv temple image detecter it works perfectly when the icon is there but the problem is when i delete the icon still the rectangle appears and it appears in wrong place all i want if there is a match show the rectangle if there is not don't show it
here is my code
public class Test123 extends AppCompatActivity {
ImageView a,b,c;
String resultImgPath,baseDir,lol;
Button x;
private static final String TAG = "Test123";
String aa,bb;
static {
if(!OpenCVLoader.initDebug()){
Log.e(TAG, "OpenCV not loaded");
} else {
Log.e(TAG, "OpenCV loaded");
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test123);
System.loadLibrary("opencv_java3");
a = (ImageView)findViewById(R.id.imageView);
b = (ImageView)findViewById(R.id.imageView2);
c = (ImageView)findViewById(R.id.imageView3);
x = (Button) findViewById(R.id.button);
baseDir = Environment.getExternalStorageDirectory().getAbsolutePath();
resultImgPath = baseDir+"/Test/result.jpg";
aa = baseDir+"/Test/d.jpg";
bb = baseDir+"/Test/dd1.jpg";
lol = baseDir+"/Test/c.jpg";
x.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Bitmap bmImg = BitmapFactory.decodeFile(aa);
int fromHere = (int) (bmImg.getHeight() * 0.06);
final Bitmap croppedBitmap = Bitmap.createBitmap(bmImg, (int) (bmImg.getWidth() * 0.3), (int) (bmImg.getHeight() * 0.94), (int) (bmImg.getWidth() * 0.6), fromHere);
String root = Environment.getExternalStorageDirectory().toString();
File myDir = new File(root + "/Test");
myDir.mkdirs();
String fname = "c.jpg";
File file = new File(myDir, fname);
if (file.exists())
file.delete();
try {
FileOutputStream out = new FileOutputStream(file);
croppedBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
a.setImageBitmap(croppedBitmap);
Bitmap bmImg2 = BitmapFactory.decodeFile(bb);
b.setImageBitmap(bmImg2);
matchingDemo(lol, bb, resultImgPath, Imgproc.TM_SQDIFF);
}
});
}
public void matchingDemo(String imgPath,String templatePath,String resPath, int matchType){
// to read the entered image from its path and make a mat object
Mat img = Imgcodecs.imread(imgPath);
Mat templ = Imgcodecs.imread(templatePath);
// Create the result matrix
int result_cols = img.cols() - templ.cols() + 1;
int result_rows = img.rows() - templ.rows() + 1;
Mat result = new Mat(result_rows, result_cols, CvType.CV_8UC3);
// performing matching and do normalization
Imgproc.matchTemplate(img, templ, result, matchType);
int type = Imgproc.THRESH_TOZERO;
Imgproc.threshold(result, result, 0.8, 1., type);
Core.normalize(result, result, 0, 1, Core.NORM_MINMAX, -1, new Mat());
// / finding the best match from minMaxLoc
Core.MinMaxLocResult mmr = Core.minMaxLoc(result);
double bb = mmr.maxVal;
Log.e("hey",bb+"");
Point matchLoc;
if (matchType == Imgproc.TM_SQDIFF || matchType == Imgproc.TM_SQDIFF_NORMED) {
matchLoc = mmr.minLoc;
} else {
matchLoc = mmr.maxLoc;
}
// draw a rectangle on searched object
Imgproc.rectangle(img, matchLoc, new Point(matchLoc.x + templ.cols(),
matchLoc.y + templ.rows()), new Scalar(0, 255, 0));
// store the result image here
Imgcodecs.imwrite(resPath, img);
Mat image = new Mat();
image =Imgcodecs.imread(resPath);
Bitmap bm = Bitmap.createBitmap(image.cols(),image.rows(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(image, bm);
c.setImageBitmap(bm);
image.release();
}
}
EDIT
i know that i need something here
if(......................)
Imgproc.rectangle(img, matchLoc, new Point(matchLoc.x + templ.cols(),
matchLoc.y + templ.rows()), new Scalar(0, 255, 0));
}
I tried to put minVal inside the if block but every picture gives me different numbers i tried with normalize and without it i can put the right number on 1 picture but other picture gives me different numbers so it is not detecting at all if the icon is visible or if it is not it givin the same issue drawing in wrong place i just need 1 number or something to draw if it is there to not draw if there is no match i don't want to have value if there is no match
Related
I am trying to develop facial recognition using opencv in android I have successfully integrated opencv with JavaCv and Javacpp I trained data images from sdcard and then recognize with same image but getting '0' confidence each time although I have change my data, but still it is showing '0' confidence even using the similar images.
private void imagePrediction() {
String trainingDir = Environment.getExternalStorageDirectory()
+ File.separator + "SpySignage_filter";
File root = new File(trainingDir);
FilenameFilter jpgFilter = new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.toLowerCase().endsWith(".jpg");
}
};
File[] imageFiles = root.listFiles(jpgFilter);
opencv_core.MatVector images = new opencv_core.MatVector(imageFiles.length);
int[] labels = new int[imageFiles.length];
int counter = 0;
int label;
opencv_core.IplImage img;
opencv_core.IplImage grayImg;
for (int i = 0; i < imageFiles.length; i++) {
// Get image and label:
img = cvLoadImage(imageFiles[i].getAbsolutePath());
label = Integer.parseInt(imageFiles[i].getName().split("\\-")[0]);
// Convert image to grayscale:
grayImg = opencv_core.IplImage.create(img.width(), img.height(), IPL_DEPTH_8U, 1);
cvCvtColor(img, grayImg, CV_BGR2GRAY);
// Append it in the image list:
images.put(counter, grayImg);
// And in the labels list:
labels[counter] = label;
// Increase counter for next image:
counter++;
}
// opencv_contrib.FaceRecognizer faceRecognizer = createFisherFaceRecognizer();
// opencv_contrib.FaceRecognizer faceRecognizer = createEigenFaceRecognizer();
// FaceRecognizer faceRecognizer = createLBPHFaceRecognizer()
opencv_contrib.FaceRecognizer faceRecognizer = com.googlecode.javacv.cpp.opencv_contrib.createLBPHFaceRecognizer();
// opencv_contrib.FaceRecognizer faceRecognizer = createLBPHFaceRecognizer();
faceRecognizer.train(images, labels);
String dataTorecognize = Environment.getExternalStorageDirectory()
+ File.separator + "SpySignage_filter";
File rootDir = new File(dataTorecognize);
File[] imagelist = rootDir.listFiles(jpgFilter);
// for (int j = 0; j < imagelist.length; j++) {
// opencv_core.IplImage testImage = cvLoadImage( imagelist[j].getAbsolutePath());
opencv_core.IplImage testImage = cvLoadImage(Environment.getExternalStorageDirectory().getAbsolutePath() + "/SpySignage_filter/2-hrithik_two.jpg");
opencv_core.IplImage greyTestImage = opencv_core.IplImage.create(testImage.width(), testImage.height(), IPL_DEPTH_8U, 1);
cvCvtColor(testImage, greyTestImage, CV_BGR2GRAY);
// And get a prediction:
// int predictedLabel = faceRecognizer.predict(greyTestImage);
// System.out.println("Predicted label: " + predictedLabel);
int n[] = new int[1];
double p[] = new double[1];
// opencv_core.IplImage ipl = MatToIplImage(m,WIDTH, HEIGHT);
// IplImage ipl = MatToIplImage(m,-1, -1);
faceRecognizer.predict(greyTestImage, n, p);
if (n[0] != -1) {
mProb = (int) p[0];
} else
mProb = -1;
// if ((n[0] != -1)&&(p[0]<95))
if (n[0] != -1) {
Toast.makeText(getApplicationContext(), "Image Recognized Confidence =" + mProb, Toast.LENGTH_LONG).show();
// return label.get(n[0]);
} else {
Toast.makeText(getApplicationContext(), "Image Not Recognized", Toast.LENGTH_LONG).show();
}
}
Help me guys, I'm creating augmented reality (unity+vuforia). I have button for screen shot screen, is work but file location on (/Data/Data/com.companyname.gamename/Files). How to change folder? (storage/emulated/0/DCIM/Camera/) .
using UnityEngine;
using System.Collections;
using System.IO;
public class SnapshotShare : MonoBehaviour
{
private AndroidUltimatePluginController androidUltimatePluginController;
Camera mainCamera;
RenderTexture renderTex;
Texture2D screenshot;
Texture2D LoadScreenshot;
int width = Screen.width;
int height = Screen.height;
string fileName;
string screenShotName = "Animal3D_";
void Start ()
{
androidUltimatePluginController = AndroidUltimatePluginController.GetInstance ();
}
public void Snapshot ()
{
StartCoroutine (CaptureScreen ());
}
public IEnumerator CaptureScreen ()
{
yield return null;
GameObject.Find ("Canvas").GetComponent<Canvas> ().enabled = false;
yield return new WaitForEndOfFrame ();
if (Screen.orientation == ScreenOrientation.Portrait || Screen.orientation == ScreenOrientation.PortraitUpsideDown) {
mainCamera = Camera.main.GetComponent<Camera> ();
renderTex = new RenderTexture (height, width, 24);
mainCamera.targetTexture = renderTex;
RenderTexture.active = renderTex;
mainCamera.Render ();
screenshot = new Texture2D (height, width, TextureFormat.RGB24, false);
screenshot.ReadPixels (new Rect (0, 0, height, width ), 0, 0);
screenshot.Apply ();
RenderTexture.active = null;
mainCamera.targetTexture = null;
}
if (Screen.orientation == ScreenOrientation.LandscapeLeft || Screen.orientation == ScreenOrientation.LandscapeRight) {
mainCamera = Camera.main.GetComponent<Camera> ();
renderTex = new RenderTexture (width, height, 24);
mainCamera.targetTexture = renderTex;
RenderTexture.active = renderTex;
mainCamera.Render ();
screenshot = new Texture2D (width, height, TextureFormat.RGB24, false);
screenshot.ReadPixels (new Rect (0, 0, width, height), 0, 0);
screenshot.Apply (); //false
RenderTexture.active = null;
mainCamera.targetTexture = null;
}
File.WriteAllBytes (Application.persistentDataPath + "/" +screenShotName+Time.frameCount+".jpg", screenshot.EncodeToJPG ());
GameObject.Find ("Canvas").GetComponent<Canvas> ().enabled = true;
}
public void LoadImage ()
{
string path = Application.persistentDataPath + "/" + screenShotName;
byte[] bytes;
bytes = System.IO.File.ReadAllBytes(path);
LoadScreenshot = new Texture2D(1,1);
LoadScreenshot.LoadImage(bytes);
GameObject.FindGameObjectWithTag ("Picture").GetComponent<Renderer> ().material.mainTexture = screenshot;
}
public void close ()
{
Application.Quit ();
}
}
Took from here (more details) and here (discussion).
I suggest you to save your captured screenshot in app location (/Data/Data/com.companyname.gamename/Files) and then use File.Move(source, dest) to move it:
if(Shot_Taken == true)
{
string Origin_Path = System.IO.Path.Combine(Application.persistentDataPath, Screen_Shot_File_Name);
// This is the path of my folder.
string Path = "/mnt/sdcard/DCIM/Inde/" + Screen_Shot_File_Name;
if(System.IO.File.Exists(Origin_Path))
{
System.IO.File.Move(Origin_Path, Path);
Shot_Taken = false;
}
}
I want to create the image of the barcode/QR code etc on my app. I have searched a lot and have found different libraries to do this task but since I am already using Zxing so i would like to work in it.
Following is the code that I have writen:
This is my Scanner Activity class:
public void handleResult(Result rawResult) {
// Do something with the result here
Log.v(TAG, rawResult.getText()); // Prints scan results
Toast.makeText(SimpleScannerActivity.this, rawResult.toString() + " WOW scanned", Toast.LENGTH_LONG).show();
Toast.makeText(SimpleScannerActivity.this, rawResult.getBarcodeFormat().toString(), Toast.LENGTH_LONG).show();
Log.v(TAG, rawResult.getBarcodeFormat().toString()); // Prints the scan format (qrcode, pdf417 etc.)
//Intent scanScreenResult= new Intent("com.aaa.fyp.ScanResultScreen");
setFormat(rawResult);
Intent nextScreen = new Intent("com.aaa.fyp.ScanResultScreen");
nextScreen.putExtra("barcode",rawResult.toString());
nextScreen.putExtra("format", rawResult.getBarcodeFormat().toString());
finish();
startActivity(nextScreen);
}
public void setFormat(Result result){
r=result.getBarcodeFormat();
System.out.println("============================== setformat main"+ r);
}
public BarcodeFormat getFormat(){
System.out.println("============================== getformat main"+ r);
return r;
}
Using the results from the above activity in ScanResultScreen activity.
public class ScanResultScreen extends SimpleScannerActivity {
ImageView scanned;
TextView bc;
TextView f;
String Barcode;
String format;
BarcodeFormat form;
#Override
public void onCreate(Bundle state) {
super.onCreate(state);
setContentView(R.layout.scan_screen_with_button);
ViewGroup layout = (ViewGroup) findViewById(R.id.scanScreenWithButton);
setContentView(layout);
Intent prevScreen = getIntent(); // gets the previously created intent
Barcode=prevScreen.getStringExtra("barcode");
bc= (TextView)findViewById(R.id.barcode_label);
bc.setText(Barcode);
format=prevScreen.getStringExtra("format");
f=(TextView) findViewById(R.id.format_label);
f.setText(prevScreen.getStringExtra("format").toString());
SimpleScannerActivity obj=new SimpleScannerActivity();
form=obj.getFormat();
d=(TextView)findViewById(R.id.date_label);
String formattedDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime());
d.setText(formattedDate);
Bitmap bitmap = null;
ImageView iv = new ImageView(this);
try {
bitmap = encodeAsBitmap(Barcode, form, 600, 300);
iv.setImageBitmap(bitmap);
} catch (WriterException e) {
e.printStackTrace();
}
layout.addView(iv);
}
private static final int WHITE = 0xFFFFFFFF;
private static final int BLACK = 0xFF000000;
Bitmap encodeAsBitmap(String contents, BarcodeFormat format, int img_width, int img_height) throws WriterException {
String contentsToEncode = contents;
if (contentsToEncode == null) {
return null;
}
Map<EncodeHintType, Object> hints = null;
String encoding = guessAppropriateEncoding(contentsToEncode);
if (encoding != null) {
hints = new EnumMap<EncodeHintType, Object>(EncodeHintType.class);
hints.put(EncodeHintType.CHARACTER_SET, encoding);
}
MultiFormatWriter writer = new MultiFormatWriter();
BitMatrix result;
try {
result = writer.encode(contentsToEncode, format, img_width, img_height, hints);
} catch (IllegalArgumentException iae) {
// Unsupported format
return null;
}
int width = result.getWidth();
int height = result.getHeight();
int[] pixels = new int[width * height];
for (int y = 0; y < height; y++) {
int offset = y * width;
for (int x = 0; x < width; x++) {
pixels[offset + x] = result.get(x, y) ? BLACK : WHITE;
}
}
Bitmap bitmap = Bitmap.createBitmap(width, height,
Bitmap.Config.ARGB_8888);
bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
return bitmap;
}
private static String guessAppropriateEncoding(CharSequence contents) {
// Very crude at the moment
for (int i = 0; i < contents.length(); i++) {
if (contents.charAt(i) > 0xFF) {
return "UTF-8";
}
}
return null;
}
Now I am getting a Null value in the variable "form". Even though I am able to get the barcodeFormat in my second activity by passing it through intent but it's in the type String. Whereas the built-in methods that I am using here requires it in BarcodeFormat that is available in Zxing.
Help!!
BarcodeFormat is an enum type. If you want to pass a String value, you have to convert it to BarcodeFormat.
For example, passing a barcode format "AZTEC":
BarcodeFormat format = Enum.valueOf(BarcodeFormat.class, "AZTEC");
Mat last;
//Mat last2;
ArrayList<Scene> scenes = new ArrayList<Scene>();
//ArrayList<Scene> scenes23 = new ArrayList<Scene>();
ArrayList<Bitmap> myImageList2 = new ArrayList<Bitmap>();
int[] myImageList = new int[]{R.drawable.baldglassy,
R.drawable.baldglassy2,
R.drawable.bandedarcherfish,
R.drawable.bandedarcherfish2,
R.drawable.bluegill,
R.drawable.bluegill2,
R.drawable.bluespotmullet};
/*Bitmap[] images2 = { BitmapFactory.decodeResource(getResources(),R.drawable.baldglassy),
BitmapFactory.decodeResource(getResources(),R.drawable.baldglassy2),
BitmapFactory.decodeResource(getResources(),R.drawable.bandedarcherfish),
BitmapFactory.decodeResource(getResources(),R.drawable.bluegill),
BitmapFactory.decodeResource(getResources(),R.drawable.bluegill2),
BitmapFactory.decodeResource(getResources(),R.drawable.bluespotmullet),
};*/
Scene refScene;
ProgressDialog progress;
//Mat imgMAT;
public void takePic1(View w) {
//Bitmap bmp32 = images[](Bitmap.Config.ARGB_8888, true);
/*for(int i=0;i<=5;i++){
Bitmap bmp32 = images[i].copy(Bitmap.Config.ARGB_8888, true);
Utils.bitmapToMat(bmp32, imgMAT);
}
Scene scene2 = new Scene(imgMAT);
scenes.add(scene2);*/
Scene scene = new Scene(last);
scenes.add(scene);
addBtn.setText("Add (" + scenes.size() + ")");
}
public void takePic2(View w) {
Mat im = last.clone();
// Imgproc.cvtColor(im, im, Imgproc.COLOR_BGR2RGB);
Bitmap bmp = Bitmap.createBitmap(im.cols(), im.rows(),
Bitmap.Config.ARGB_8888);
Utils.matToBitmap(im, bmp);
matchDrawArea.setImageBitmap(bmp);
refScene = new Scene(last);
}
when i use a bitmap array, the app crashes
it says that change the type of my int array to Scene. But it is impossible. Thanks in advance to those who will help.
here is the scene class
public class Scene {
final Mat image;
final Mat descriptors = new Mat();
final MatOfKeyPoint keypoints = new MatOfKeyPoint();
boolean firstTime = true;
public Scene(Mat image) {
this.image = image.clone();
// DetectUtility.analyze(image, keypoints, descriptors);
}
public void preCompute() {
if (firstTime) {
DetectUtility.analyze(image, keypoints, descriptors);
firstTime = false;
}
}
public SceneDetectData compare(Scene frame, boolean isHomogrpahy, boolean imageOnly) {
// Info to store analysis stats
SceneDetectData s = new SceneDetectData();
// Detect key points and compute descriptors for inputFrame
MatOfKeyPoint f_keypoints = frame.keypoints;
Mat f_descriptors = frame.descriptors;
this.preCompute();
frame.preCompute();
// Compute matches
MatOfDMatch matches = DetectUtility.match(descriptors, f_descriptors);
// Filter matches by distance
MatOfDMatch filtered = DetectUtility.filterMatchesByDistance(matches);
// If count of matches is OK, apply homography check
s.original_key1 = (int) descriptors.size().height;
s.original_key2 = (int) f_descriptors.size().height;
s.original_matches = (int) matches.size().height;
s.dist_matches = (int) filtered.size().height;
if (isHomogrpahy) {
MatOfDMatch homo = DetectUtility.filterMatchesByHomography(
keypoints, f_keypoints, filtered);
Bitmap bmp = DetectUtility.drawMatches(image, keypoints,
frame.image, f_keypoints, homo, imageOnly);
s.bmp = bmp;
s.homo_matches = (int) homo.size().height;
return s;
} else {
Bitmap bmp = DetectUtility.drawMatches(image, keypoints,
frame.image, f_keypoints, filtered, imageOnly);
s.bmp = bmp;
s.homo_matches = -1;
return s;
}
}
}
I have create the Handler inside the activity onCreate method. This Hanlder is responsible to take screen shots after 10 seconds. Inside the run method I have used while(flag==true) and screen the capture util flag==false, But this stuck my activity. I can not able to work. And it take the screen shot over again and again of same image because of actvity is stuck.
How I can work with my screen and what I am doing handler take the screen shot after 10 seconds?
The while loop stuck my app.
It Take picture but I am not able to work with my activity.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
flag = true;
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
while (flag == true) {
String SCREENSHOTS_LOCATIONS = Environment
.getExternalStorageDirectory().toString() + "/re/";
// Get root view
View view = getWindow().getDecorView().getRootView();
// Create the bitmap to use to draw the screenshot
final Bitmap bitmap = Bitmap.createBitmap(view.getWidth(),
view.getHeight(), Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(bitmap);
// Get current theme to know which background to use
final Theme theme = getTheme();
final TypedArray ta = theme
.obtainStyledAttributes(new int[] { android.R.attr.windowBackground });
final int res = ta.getResourceId(0, 0);
final Drawable background = getResources().getDrawable(res);
// Draw background
background.draw(canvas);
// Draw views
view.draw(canvas);
FileOutputStream fos = null;
try {
final File sddir = new File(SCREENSHOTS_LOCATIONS);
if (!sddir.exists()) {
sddir.mkdirs();
}
fos = new FileOutputStream(SCREENSHOTS_LOCATIONS + x
+ ".jpg");
x++;
if (fos != null) {
if (!bitmap.compress(Bitmap.CompressFormat.JPEG,
90, fos)) {
Log.d("ScreenShot", "Compress/Write failed");
}
fos.flush();
fos.close();
}
} catch (Exception e) {
}
}
}
}, 1000);
}
Maybe try using an AsyncTask or other thread. The postDelayed() function attaches to the main UI thread and locks up your app until run() is finished (which never happens because flag never equals false so the while loop becomes infinite?).
Here is an example using the ScheduledThreadPoolExecutor:
private ScheduledThreadPoolExecutor exec = null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
flag = true;
exec = new ScheduledThreadPoolExecutor(5);
long interval = (long) 10; // 10 seconds for you
exec.scheduleAtFixedRate(new savePicTask(), 0, interval, TimeUnit.SECONDS);
}
class savePicTask implements Runnable {
#Override
public void run() {
while (flag == true) {
String SCREENSHOTS_LOCATIONS = Environment
.getExternalStorageDirectory().toString() + "/re/";
// Get root view
View view = getWindow().getDecorView().getRootView();
// Create the bitmap to use to draw the screenshot
final Bitmap bitmap = Bitmap.createBitmap(view.getWidth(),
view.getHeight(), Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(bitmap);
// Get current theme to know which background to use
final Theme theme = getTheme();
final TypedArray ta = theme
.obtainStyledAttributes(new int[] { android.R.attr.windowBackground });
final int res = ta.getResourceId(0, 0);
final Drawable background = getResources().getDrawable(res);
// Draw background
background.draw(canvas);
// Draw views
view.draw(canvas);
FileOutputStream fos = null;
try {
final File sddir = new File(SCREENSHOTS_LOCATIONS);
if (!sddir.exists()) {
sddir.mkdirs();
}
fos = new FileOutputStream(SCREENSHOTS_LOCATIONS + x
+ ".jpg");
x++;
if (fos != null) {
if (!bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fos)) {
Log.d("ScreenShot", "Compress/Write failed");
}
fos.flush();
fos.close();
}
} catch (Exception e) {
}
}
}
}
EDIT 1:
This code works for me except I am using
numberOfSeconds = 0.5;
ScheduledThreadPoolExecutor exec = new ScheduledThreadPoolExecutor(5);
long interval = (long) (1000* numberOfSeconds); // numberOfSeconds = 10 for you
exec.scheduleAtFixedRate(new savePicTask(), 0, interval, TimeUnit.MILLISECONDS);
And instead of taking a screenshot I am taking a picture with the camera. So I'm not sure why it's not working for you.