public void hide(boolean refresh) { container.remove(layout); if (showMeasurements.isSelected()) { container.remove(measurements); showMeasurements.setSelected(false); } if (refresh) core.refreshDisplay(); }
public void toggleShowMeasurements() { if (showMeasurements.isSelected()) { measurements.setStructures(currentNucId, currentStructureIdx); measurements.setObjects(list.getSelectedValues()); this.container.add(measurements); } else this.container.remove(measurements); core.refreshDisplay(); }
// init also call init from superclass public void init() { super.init(); Window w = s.getFullScreenWindow(); w.setFocusTraversalKeysEnabled(false); // just be a tab button, not just jump to next form w.addKeyListener(this); mess = "Press escape to exit"; }
private void setSortKeys() { if (currentChannels != null && currentChannels.length == 1) { MeasurementKey mkey = new MeasurementKey(new int[] {currentChannels[0].getIdx()}, MeasurementObject.Number); System.out.println("Query:" + mkey.toString()); ((ObjectManagerLayout) layout).setKeys(Core.getExperiment().getKeys().get(mkey)); } else { ((ObjectManagerLayout) layout).unableSortKeys(); } }
public void startThreads() { directTransferThread.start(); persistentQueue.startThreads(); final TimerTask task = new TimerTask() { @Override public void run() { maybeStartRequests(); } }; Core.schedule(task, 3000, 3000); }
public void templateMatching() { System.loadLibrary(Core.NATIVE_LIBRARY_NAME); int match_method = 5; int max_Trackbar = 5; Mat data = Highgui.imread("images/training_data/1" + "/data (" + 1 + ").jpg"); Mat temp = Highgui.imread("images/template.jpg"); Mat img = data.clone(); int result_cols = img.cols() - temp.cols() + 1; int result_rows = img.rows() - temp.rows() + 1; Mat result = new Mat(result_rows, result_cols, CvType.CV_32FC1); Imgproc.matchTemplate(img, temp, result, match_method); Core.normalize(result, result, 0, 1, Core.NORM_MINMAX, -1, new Mat()); double minVal; double maxVal; Point minLoc; Point maxLoc; Point matchLoc; // minMaxLoc( result, &minVal, &maxVal, &minLoc, &maxLoc, Mat() ); Core.MinMaxLocResult res = Core.minMaxLoc(result); if (match_method == Imgproc.TM_SQDIFF || match_method == Imgproc.TM_SQDIFF_NORMED) { matchLoc = res.minLoc; } else { matchLoc = res.maxLoc; } // / Show me what you got Core.rectangle( img, matchLoc, new Point(matchLoc.x + temp.cols(), matchLoc.y + temp.rows()), new Scalar(0, 255, 0)); // Save the visualized detection. Highgui.imwrite("images/samp.jpg", img); }
public static Mat getCCH(Mat image) { ArrayList<MatOfPoint> contours = new ArrayList<MatOfPoint>(); Mat hierarchy = new Mat(); Imgproc.findContours( image, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_NONE); Mat chainHistogram = Mat.zeros(1, 8, CvType.CV_32F); int n = 0; MatOfPoint2f approxCurve = new MatOfPoint2f(); for (MatOfPoint contour : contours) { // get the freeman chain code from the contours int rows = contour.rows(); // System.out.println("\nrows"+rows+"\n"+contour.dump()); int direction = 7; Mat prevPoint = contours.get(0).row(0); n += rows - 1; for (int i = 1; i < rows; i++) { // get the current point double x1 = contour.get(i - 1, 0)[1]; double y1 = contour.get(i - 1, 0)[0]; // get the second point double x2 = contour.get(i, 0)[1]; double y2 = contour.get(i, 0)[0]; if (x2 == x1 && y2 == y1 + 1) direction = 0; else if (x2 == x1 - 1 && y2 == y1 + 1) direction = 1; else if (x2 == x1 - 1 && y2 == y1) direction = 2; else if (x2 == x1 - 1 && y2 == y1 - 1) direction = 3; else if (x2 == x1 && y2 == y1 - 1) direction = 4; else if (x2 == x1 + 1 && y2 == y1 - 1) direction = 5; else if (x2 == x1 + 1 && y2 == y1) direction = 6; else if (x2 == x1 + 1 && y2 == y1 + 1) direction = 7; else System.out.print("err"); double counter = chainHistogram.get(0, direction)[0]; chainHistogram.put(0, direction, ++counter); System.out.print(direction); } } System.out.println("\n" + chainHistogram.dump()); Scalar alpha = new Scalar(n); // the factor Core.divide(chainHistogram, alpha, chainHistogram); System.out.println("\nrows=" + n + " " + chainHistogram.dump()); return chainHistogram; }
private void sort(String key, Object3DGui[] objectsGui, int structureIdx) { Object3DGui.setAscendingOrger(((ObjectManagerLayout) layout).getAscendingOrder()); HashMap<Integer, BasicDBObject> objects = Core.getExperiment().getConnector().getObjects(currentNucId, structureIdx); boolean notFound = false; for (Object3DGui o : objectsGui) { BasicDBObject dbo = objects.get(o.getLabel()); if (dbo != null) { if (dbo.containsField(key)) o.setValue(dbo.getDouble(key)); else { o.setValue(-1); notFound = true; } } } if (notFound) ij.IJ.log("Warning measurement: " + key + " not found for one or several objects"); Arrays.sort(objectsGui); }
public void show(boolean refresh) { container.add(layout); if (refresh) core.refreshDisplay(); }
@Override public void startElement(String namespaceURI, String localName, String qName, Attributes atts) { state = findState(qName); String at; if (state != XmlState.BDN && !valid) { logger.error("BDN tag missing"); } txt = null; switch (state) { case UNKNOWN: logger.error("Unknown tag " + qName + "\n"); break; case BDN: if (valid) { logger.error("BDN must be used only once"); } else { valid = true; } break; case NAME: at = atts.getValue("Title"); if (at != null) { title = at; logger.trace("Title: " + title + "\n"); } break; case LANGUAGE: at = atts.getValue("Code"); if (at != null) { language = at; logger.trace("Language: " + language + "\n"); } break; case FORMAT: at = atts.getValue("FrameRate"); if (at != null) { fps = SubtitleUtils.getFps(at); fpsXml = XmlFps(fps); logger.trace("fps: " + ToolBox.formatDouble(fps) + "\n"); } at = atts.getValue("VideoFormat"); if (at != null) { String res = at; for (Resolution r : Resolution.values()) { if (res.length() == 4 && res.charAt(0) != '7') { // hack to rename 480p/576p to 480i/576i res = res.replace('p', 'i'); } if (r.getResolutionNameForXml().equalsIgnoreCase(res)) { resolution = r; logger.trace("Language: " + r.getResolutionNameForXml() + "\n"); break; } } } break; case EVENTS: at = atts.getValue("NumberofEvents"); if (at != null) { int n = ToolBox.getInt(at); if (n > 0) { /* number of subtitles read from the xml */ Core.setProgressMax(n); } } break; case EVENT: pic = new SubPictureXml(); subPictures.add(pic); int num = subPictures.size(); logger.info("#" + num + "\n"); Core.setProgress(num); at = atts.getValue("InTC"); if (at != null) { pic.setStartTime(timeStrXmlToPTS(at, fpsXml)); if (pic.getStartTime() == -1) { pic.setStartTime(0); logger.warn("Invalid start time " + at + "\n"); } } at = atts.getValue("OutTC"); if (at != null) { pic.setEndTime(timeStrXmlToPTS(at, fpsXml)); if (pic.getEndTime() == -1) { pic.setEndTime(0); logger.warn("Invalid end time " + at + "\n"); } } if (fps != fpsXml) { pic.setStartTime((pic.getStartTime() * 1001 + 500) / 1000); pic.setEndTime((pic.getEndTime() * 1001 + 500) / 1000); } at = atts.getValue("Forced"); pic.setForced(at != null && at.equalsIgnoreCase("true")); if (pic.isForced()) { numForcedFrames++; } int dim[] = resolution.getDimensions(); pic.setWidth(dim[0]); pic.setHeight(dim[1]); break; case GRAPHIC: pic.setImageWidth(ToolBox.getInt(atts.getValue("Width"))); pic.setImageHeight(ToolBox.getInt(atts.getValue("Height"))); pic.setOfsX(ToolBox.getInt(atts.getValue("X"))); pic.setOfsY(ToolBox.getInt(atts.getValue("Y"))); pic.storeOriginalOffsets(); txt = new StringBuffer(); break; } }