I'm using for my app the RedLaser library for barcode scanning (which is built off Zxing, I believe). Everything is working fine, while in scanning mode, any barcode that comes within view is scanned, but I don't want that, I want only barcodes that are aligned in a scanning area to be considered and the rest to be ignored.
The redlaser sample app, after which I implemented the library in my own app, had a rectangle on the layout of the scanning activiy, however that was ignored, as barcodes from any part of the screen were scanned and taken into account by the sample app.
Bottom line: I want my scanning activity to compare the location of the currently detected barcode and see if it is within the bounds of the "scanning area", if it is not then it won't be read.
Here is the code for the adjustment of the "scanning area":
viewfinderView = findViewById(R.id.view_finder);
LayoutParams params = new LayoutParams((int)(mDisplay.getWidth() * .75f),
(int)(mDisplay.getHeight() * .33f));
params.gravity = Gravity.CENTER;
viewfinderView.setLayoutParams(params);
The following code doesn't do anything, I just wrote it to exemplify the how everything works (since I don't have the source files for the Redlaser library), like the barcodelocation.
Set<BarcodeResult> allResults = (Set<BarcodeResult>) scanStatus.get(Status.STATUS_FOUND_BARCODES);
for( BarcodeResult s : allResults)
{
ArrayList<PointF> barcodelocation = s.barcodeLocation;
float x = barcodelocation.get(0).x;
float y = barcodelocation.get(0).y;
//there will be 4 points to each scanned barcode => 8 float's/barcode
}
Sorry for the long post, but I've been on this issue for a while now and I'm really stuck.
Any help is appreciated!
Managed to find a solution on the Redlaser site: turning the view into a rect then comparing the barcode location with that using .contain :
Rect scanningArea = new Rect(viewfinderView.getLeft(), viewfinderView.getTop(), viewfinderView.getRight(), viewfinderView.getBottom());
if(latestResult.iterator().hasNext())
{
boolean isInside = true;
ArrayList<PointF> barcodelocation = latestResult.iterator().next().barcodeLocation;
for (int i = 0; i < barcodelocation.size(); i++)
{
int x = (int) barcodelocation.get(i).x;
int y = (int) barcodelocation.get(i).y;
if (!scanningArea.contains(x, y))
{
isInside = false;
}
}
if (isInside)
{
//do stuff here
}
}
I'm still working on a few issues, but this question is answered now. Gonna go ahead and give myself a pat on the back. :)
Related
I am writing an app that generates Maths worksheets for school students. It will, for example, generate 2 to 5 pages of simple Maths questions and 1 to 2 pages of answers. The PDF can be saved to file and loaded again later. Then it has a print function that can print all the pages. I want to make it skip printing the answer pages.
Is it possible to automatically identify which pages are the answer pages? I can only think of a workaround by making those answer pages have special height or width but not even sure if this works. Are there any better ways to do this?
Ok, I continued the project and used the following method: when constructing the PDF, I put the word "Answer on the top left corner with a gray rectangle surrounding it drawn with drawRect(). Then before the actual printing, I used the following code inside the PrintDocumentAdapter() class to check whether the color of the pixel 0,0 is gray or not.
#Override
public void onStart() {
if (parcelFileDescriptor != null) {
try {
pdfRenderer = new PdfRenderer(parcelFileDescriptor);
} catch (IOException e) {
e.printStackTrace();
}
}
int tempTotal = pdfRenderer.getPageCount();
Bitmap[] tempBitmap = new Bitmap[tempTotal];
finalTotal = tempTotal;
for (int pageNum = 0; pageNum < tempTotal; pageNum++) {
PdfRenderer.Page tempPage = pdfRenderer.openPage(pageNum);
tempBitmap[pageNum] = Bitmap.createBitmap(WS_WIDTH, WS_HEIGHT, Bitmap.Config.ARGB_8888);
tempPage.render(tempBitmap[pageNum], null, null, PdfRenderer.Page.RENDER_MODE_FOR_PRINT);
if (tempBitmap[pageNum].getPixel(0, 0) == Color.GRAY) {
finalTotal--;
}
tempPage.close();
}
}
It works fine. At least should cause no problem if the users only attempt to print PDF files constructed with my app. :P
Please tell me if you know a better way to do this. Thanks!
I have a Java plugin for a larger application that does image analysis using the ImageJ library. One client who switched to our software has been using Groovy scripts to define specific rules and parameters for when they perform the analysis in ImageJ. They would like our software to be able to accept the Groovy scripts as well, as they'll be working within our GUI as well as ImageJ.
They will provide a written script.groovy to the plugin, but I won't always know exactly what parameters, methods, and classes are present and what changes to the logic are in the .groovy file.
I've been looking into the GroovyClassLoader documentation, and after referencing Groovy in Action, 2nd Edition I have a better idea of how to create and send bindings and whatnot but I can't figure out where to start writing the logic for interpreting the contents of a static Groovy file. An ideal solution would be the user having one script that works in both programs, and my plugin determines what is relevant.
Is there any way to parse out individual parts of a Groovy file so that I might map them to our parameters and change the Java plugin's behavior accordingly?
Edit: Context
Our software performs real-time image analysis on stained tissue slides. Some of our users also use "Program X" within its GUI to perform analysis on images that have already been taken. The Java plugin accesses the logic from the other program, allowing our users to use features they're familiar with in real-time.
The Groovy script file.groovy that the user gives to Program X has some functions that feed data to the UI portions of the software that we don't need. I'd like to only parse our relevant portions of the script.
Edit: Sample File, and what I'd like to parse:
The .groovy file begins with some parameters, which are no use to me, as well as some methods for defining image background, also no use as my program does this automatically, where "Program X" does not:
/* imports */
//PARAMETER AREA//
//PARAMETERS FOR IMAGES WITH UM//
double requested_pixel_size = 0.5
double background_radius = 8
double median_filter_radius = 0
double sigma = 1.5
double minimum_area = 10
double maximum_area = 400
double threshold = 0.1
//PARAMETER AREA ENDS//
def openingReconstruction(final ImageProcessor ip, final ImageProcessor ipBackground, final double radius, final double maxBackground) {
final RankFilters rf = new RankFilters()
ipBackground.setRoi(ip.getRoi())
rf.rank(ipBackground, radius, RankFilters.MIN)
ByteProcessor bpMask = null
if (!Double.isNaN(maxBackground) && maxBackground > 0) {
int w = ip.getWidth()
int h = ip.getHeight()
for (int i = 0; i < w * h; i++) {
if (ipBackground.getf(i) > maxBackground) {
if (bpMask == null)
bpMask = new ByteProcessor(w, h)
bpMask.setf(i, 1f)
}
}
if (bpMask != null) {
rf.rank(bpMask, radius * 2, RankFilters.MAX)
for (int i = 0; i < w * h; i++) {
if (bpMask.getf(i) != 0f) {
ipBackground.setf(i, Float.NEGATIVE_INFINITY)
}
}
}
}
Then there are some area which actually enhance our program, and I need to be able to implement:
def detect(double key_value, PathObject parentObject, int Choose_detection_image, ParameterList params) {
def viewer = QPEx.getCurrentViewer()
ImageData<BufferedImage> imageData = viewer.getImageData()
println("Program starts.....")
The above code snippet will eventually call a modified version of the detection class which I need:
detect(key_value, parentObject, Choose_detection_image, params)
class WatershedCellDetection2 {
protected ObjectDetector<BufferedImage> createDetector(ImageData<BufferedImage> imageData, ParameterList params, double key_value) {
ObjectDetector<BufferedImage> detector = new NewCellDetector(key_value)
//insert the key_value in original detector.
return new DetectorWrapper<>(detector)
}
There are a few overloaded methods and other versions of the WatershedCellDetection that are used depending on what parameters are present, but as long as I know how to parse out one I can determine which one is best for each scenario.
There is a lot of code built into the functions that do things like update the help text in the GUI of "Program X" that are irrelevant to my program's UI since this is all interacting with a Java plugin of a C# program.
I am new to Android Development and I have to make line graph.
The graph I am trying to make is very customized i.e. using images as the data point.
There are lots of open source libraries but I cant use images as data points and they should be clickable.
Chart I am trying to make
i'm to late in answering this question but i have done recently this type of work using MPChartAndroid
this is the simple code to set icons you can check complete example at this link
ArrayList<Entry> values = new ArrayList<>();
for (int i = 0; i < count; i++) {
float val = (float) (Math.random() * range) - 30;
values.add(new Entry(i, val, getResources().getDrawable(R.drawable.star)));
}
LineDataSet set1;
set1 = LineDataSet(values, "")
set1.setDrawIcons(true)
chart.setData(data);
Looking for a GWT DataGrid component which implements infinite scroll, BUT also makes sure to discard the results no longer visible on the screen : such as the previously loaded results that are not shown anymore.
This is to avoid a memory hog.
I've been trying to find this on Google, but no luck so far.
Please note : I could take a JS library and adapt it to what I need, but I don't think it would work good with GWT's DataGrid component.
Edit: I am interested specifically in an infinite scroll which ALSO discards/releases the topmost results that are not visible (and loads them up as appropriate).
Any ideas ?
As a matter of fact the showcase example has an infinite scrolling CellList. (you can find the code there).
Although this was done with a CellList the same principles should also apply to a DataGrid.
Check out the ShowMorePagerPanel.java file.
Update:
The onScroll function of ShowMorePagerPanel.java will add the new records at the bottom. However you can easily change the behavior:
Something along the lines (not tested tough):
HasRows display = getDisplay();
if (display == null) {
return;
}
boolean loadData = false;
// If scrolling up, change newStart
int oldScrollPos = lastScrollPos;
lastScrollPos = scrollable.getVerticalScrollPosition();
// get the current visible Range
Range currentRange = display.getVisibleRange();
if (oldScrollPos >= lastScrollPos) {
int newStart = Math.max(
currentRange.getStart() - incrementSize,0);
loadData = true;
}
int maxScrollTop = scrollable.getWidget().getOffsetHeight()
- scrollable.getOffsetHeight();
if (lastScrollPos >= maxScrollTop) {
// We are near the end, so increase the page size.
int newPageSize = Math.min(
display.getVisibleRange().getLength() + incrementSize,
display.getRowCount());
loadData = true;
}
if (loadData) {
display.setVisibleRange(newStart, newPageSize);
}
how to know which screen is open/ in foreground in blackberry? In other words, can we get a name of the screen which is currently open in BB. It can include other app, call logs, messages etc. , not necessarily my APP. Can this be done? Thanks..
There are three methods in ApplicationDescriptor that can help you figure out the currently foregrounded app. Getting to the Application object itself may be a little more difficult, but you can at least discover the ApplicationDescriptor.
ApplicationManager mgr = ApplicationManager.getApplicationManager();
final ApplicationDescriptor[] vApps = mgr.getVisibleApplications();
int foregroundId = mgr.getForegroundProcessId();
for(int i = 0; i < vApps.length; i++) {
int id = mgr.getProcessId(vApps[i]);
if(id == foregroundId) {
// we have a winner!
}
}
Hopefully this is what you mean:
if (Application.getApplication().isForeground()) {
Screen scr = UiApplication.getUiApplication().getActiveScreen();
}