The problem I am trying to solve relates to block-matching or image-within-image recognition. This is an algorithm problem I am working on in java, but computationally, my computer can't handle generating all the combinations at one time.
I see an image, extract the [x,y] of every black pixel and create a set for that image, such as
{[8,0], [9,0], [11,0]}
The set is then augmented so that the first pixel in the set is at [0,0], but the relationship of the pixels is preserved. For example, I see {[8,0], [9,0]} and change the set to {[0,0], [1,0]}. The point of the extraction is that now if I see {[4,0], [5,0]}, I can recognize that basic relationship as two vertically adjacent pixels, my {[0,0], [1,0]}, since it is the same image but only in a different location.
I have a list of these pixel sets, called "seen images". Each 'seen image' has a unique identifier, that allows it to be used as a nested component of other sets. For example:
{[0,0], [1,0]} has the identifier 'Z'
So if I see:
{[0,0], [1, 0], [5,6]}
I can identify and store it as:
{[z], [5, 6]}
The problem with this is that I have to generate every combination of [x,y]'s within the pixel set to check for a pattern match, and to build the best representation. Using the previous example, I have to check:
{[0,0], [1,0]},
{[0,0], [5,6]},
{[1,0], [5,6]} which is {[0,0], [4,5]}
{[0,0], [1,0], [5,6]}
And then if a match occurs, that subset gets replaced with it's ID, merged with the remainder of the original set, and the new combination needs to be checked if it is a 'seen image':
{[z],[5, 6]}
The point of all that is to match as many of the [x,y]'s possible, using the fewest pre-existing pieces as components, to represent a newly seen image concisely. The greedy solution to get the component that matches the largest subset is not the right one. Complexity arises in generating all of the combinations that I need to check, and then the combinations that spawn from finding a match, meaning that if some match and swap produces {[z], [1,0], [2,0]}, then I need to check (and if matched, repeat the process):
{[z], [1,0]}
{[z], [2,0]}
{[1,0], [2,0]} which is {[0,0], [1,0]}
{[z], [1,0], [2,0]}
Currently I generate the pixel combinations this way (here I use numbers to represent pixels 1 == [x,y]) Ex. (1, 2, 3, 4): Make 3 lists:
1.) 2.) 3.)
12 23 34
13 24
14
Then for each number, for each list starting at that number index + 1, concatenate the number and each item and store on the appropriate list, ex. (1+23) = 123, (1+24) = 124
So those are all the combinations I need to check if they are in my 'seen images'. This is a bad way to do this whole process. I have considered different variations / optimizations, including once the second half of a list has been generated (below the ----), check every item on the list for matches, and then destroy the list to save space, and then continue generating combinations. Another option would be to generate a single combination, and then check it for a match, and somehow index the combinations so you know which one to generate next.
How to optimize what I am doing for a set of ~million items. I also have not yet come up with a non-recursive or efficient way to handle that each match generates additional combinations to check.
I'm relatively new to java and to image processing ... What I've done so far is make a simple application which opens the webcam and can take and save a picture. Ive then loaded the image pixel data into a 2d array. How then do I do what is known as 'fast fourier transform' on it from here?
I am trying to process an array of pixels, checking each within a 5*5 mask. Ive declared my mask as a 2d array and get the pixel values within a nested for loop. Im getting an ArrayIndexOutOfBoundsException at the line:
mask[0][4] = dsIm.red[i-1][j+3];
Have I declared my mask wrong for a 5*5 mask. Is my logic wrong?
I won't give all the code, but basically Im trying to check all 25 pixel values within the mask:
int [][] mask = new int[5][5]; System.out.println("We are in the method just written"); //loop one loop for(int i = 1; i <= h-2; i++) { for(int j = 1; j<=w-2; j++)
class mmm { public static void main(String[] args) { OcrEngine ocr = new OcrEngine(); ocr.setImage(ImageStream.fromFile("pp.tif")); // ocr.setImage((IImageStream) new File("pp.tif"));
[Code] ....
In above code giving error .
Exception in thread "main" com.aspose.ms.System.IO.FileNotFoundException: Can't find file: pp.tiff.
Where i am wrong. I am trying to pass all formt(.png,.gif,.jpg) images. I am giving proper path ....
Private Sub cmdDeleteMessage_Click() If txtMessage.Text = "" Then a = MsgBox("No message to delete!", vbInformation, "") Else: If MsgBox("Do you want to create a new message?", vbYesNo, "New") = vbNo Then Exit Sub txtMessage.Text = "" Pic.Picture = LoadPicture()
[Code] .....
Is these codes of the Block cipher encryptor for text-to-image algorithm (B-TTIE algorithm) by Abusukhon 2013? If not, how to make it the same with B-TTIE algorithm?
I have the following task given to me (to be solved in NetBeans) :
View the contents of the file tuinman.txt: each line has a (real) number, followed by a line text.
Write the readGardener () method that reads the file completely. Only if the number is negative, write the rest of the line. (For each input line, a new line output.)
Extra: Adjust your method so you get the text after each negative number, written "word by word", among themselves. A word can contain characters that are not "letters" are (,,. '") - ,this you may ignore.
"tuinman.txt" is dutch for "gardener.txt". This txt file is located in the same map where build,nbproject,src, etc... are located. I couldn't solve this task so i looked at the solution. It didn't work... So i tried the solution of the extra bit:
public class Methods { public void readGardener() throws FileNotFoundException {
[Code] ....
The txt file is added as an attachment to this post.
The weird thing is, the first thing the program prints is "Van" "morgen" "ijlt",... wich are words from line 19 in the txt file. All the ones before line 19 the program won't print, even if the number is negative. Even weirder, the next thing that is printed after line 19 is the NUMBER from line 20, nowhere in this code do i tell the program to print a number, and yet it does... But that's not all! From line 19 on, he just prints every single thing in the document except for the negative number, if your mind didn't explode already, it sure did now!
So in short: I need some code that prints all the lines from the txt files that start with a negative number. Only the text may be printed though, there may be no numbers in the output!
The txt file, i couldn't add it as a attachment
123 -456,12 De tuinman en de dood 184,67 was hij, Kees, de enige die het zag, want niemand lette d'r op... -845,14 -8,12452 Een Perzisch Edelman: 157,24 Dus daar gaan we dan.
I'm having trouble setting up a test for my combination method.Here's the method (It basically finds the most amount of characters that both substrings share and combines the two using the number of shared characters as a breaking point):
public static String combination(String str1, String str2, int overlap) { assert str1 != null : "Violation of: str1 is not null"; assert str2 != null : "Violation of: str2 is not null"; assert 0 <= overlap && overlap <= str1.length() && overlap <= str2.length() && str1.regionMatches(str1.length() - overlap, str2, 0, overlap) : "" + "Violation of: OVERLAPS(str1, str2, overlap)";
combo is the private CombinationLocker object I created within the Locker class. Do I need to pass the combo object on to the CombinationLock class? For reason, I do not comprehend, the combination password from the main class is not passing through to the CombinationLock class, and the combination values are all zero.
I am teaching myself AWT/Swing ... It concerns an application that creates dynamic graphics using the Graphics class. I understand that the code that creates graphics should be put in a "paintComponent" method of a (descendant of a) JPanel class. And that when you want to change something on this panel outside "paintComponent", you have to call the "repaint" method, that somehow causes "paintComponent" to be invoked.
However, I don't fully understand the explanation of the example at [URL]... . It concerns an application that moves a red square when a mouse button is clicked. The code can be found at the link, but I also repeat it below.
This code indeed works. However, I don't understand why. The explanation at the Oracle site is the following.
Because we are manually setting the clip, our moveSquare method invokes the repaint method not once, but twice. The first invocation tells Swing to repaint the area of the component where the square previously was (the inherited behavior uses the UI Delegate to fill that area with the current background color.) The second invocation paints the area of the component where the square currently is.
However, what I don't understand: when repaint is first invoked, squareX and squareY still have their old values. If the invocation of repaint simply causes an invocation of paintComponent, then paintComponent should draw a red square at (squareX, squareY). Just like the second invocation of repaint causes paintComponent to draw a red suare at the new values of (squareX, squareY). Instead, the first invocation results in the red square being wiped out by the background color.
So apparently, the first invocation of repaint does not simply cause an invocation of paintComponent. What does it do?
I need to use a counter to keep track of user's input. In this class I am trying to create a combination lock that takes three strings. In the tester class the user inserts three strings and both are compared to see if users input matches correct combination. I have no errors only problem is the setPosition method. My output is always false.
public class CombinationLock { private String first; private String second; private String third; private String firstGuess; private String secondGuess; private String thirdGuess; private boolean open; private int counter;
I am working on a project in which I have three box (as of now) and each box will have some color of balls. So I am storing them in a Map of String and List of String as mention below.
Map<String, List<String>> boxBallMap = new LinkedHashMap<String, List<String>>();
Basis on the above input, I need to return a mapping which will be List<Map<String, String>>, let's say for above input, below mapping would be return as an output -
Here if you see, each row has alternate color of balls for each box - meaning blue for box1, red for box2, orange for box3 in first row. I cannot have same color of balls in each row. So this combination is not possible as it has same color of balls for two boxes in one row.
And also, in the second row, I won't use those balls which have been used in the first row for that box. In second row, box1 has red why? bcoz blue was already used in the first row for box1 and box3 has blue and no box2 in second row.
The output combination is getting generated basis on the input being passed as shown above.
Below algorithm might work but still not sure how should I fit this in the code -
- sort the boxes by the number of balls they have in it (ascending, from the smallest to the largest box). - while there are colors left - loop over the sorted list of boxes - in each iteration pick a color from the box (if there is one left), that is not already picked in the current iteration (of the while loop)
I need to write a program that checks whether a Java source-code file has correct pairs of grouping symbols and the program must implement the Stack<E> class to solve this problem.
Here is the file: [a({b,c}x{d,e})%x] (1+(2-3)/4+[(a-({b+c}*5)/2)+e] (a{b(c]}a)
I tried something like this, but I'm not exactly sure what I am doing wrong:
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; import java.util.Stack; public class Driver {
I'm working on a Java matching game and I'm having a hard time wrapping my mind around it. What I'm having trouble with is how exactly to create an array so that my squares have random values. Then how do I get it to reveal and compare those values by clicking on two of them? Here is what I have so far:
I am having some trouble with this program. The assignment is to write a program, given a seven-digit phone number, uses a PrintStream object to write to a file every possible seven-letter word combination that corresponds to that number. I have to avoid using 0 or 1. Here is my code.
import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintStream; import java.util.Scanner; public class TelephoneGenerator { String phoneNumber; char numberLetters[][] = {
[Code] ....
I am getting an error dealing with the main class.
I need a java program for getting name and address matching from oracle database. I need get all the customer name and address belonging to same person even if there is slight name and address changes are there.
James Smith 123 Broadway Av Brownville, ME 04415
James S 123 Brodway Avenue Brownville Junction, ME 04451
I am unable to get a best code for this and trying since long time.
I am trying to write a program that checks for parentheses matching using stacks.This is my ArrayStack class.
public class ArrayStack{ private final int DEFAULT_SIZE=10; public int tos; Object[] array; public ArrayStack(){ array=new Object[DEFAULT_SIZE];
[Code] ....
But the problem is when I compile matching I get an error as unreported exception EmptyStackException.must be caught or declared to be thrown. I think the problem is with exceptions which I don't have a good knowledge of.
I'm creating a card game and I'm having trouble getting a card gif to display. A card is drawn from an 52 card deck arraylist, and I then need to match that drawn card with the similarly named gif in an arraylist of card gifs, to display the gif on a card GUI. I have put my game, card, deck and graphical class below:
Card - public class Card { public String number; public String suit; public Card(String n, String s) { number = n; suit = s;
[Code] ....
The arrayList of card gifs (which contains all 52 gifs for the cards) is in the graphical class and my arrayList that contains the deck of cards in textual form (that I've imported from a textfile) is in deck. The names of the gifs in the gif arraylist are the same as the card names in my textual card arraylist (for example, 3h.gif is 3h in my card arraylist), so I believe I can use a .equals statement to match the card that has been drawn to the gif.
Here is what the gifs look like in their folder, which is an arraylist in my graphical class :
Here is what the drawn card looks like after the textual card arraylist has been shuffled:
The brown card in that image isn't the displayed card that has been drawn, it's just a graphical deck that I put in, I can't get the card that has been drawn on the GUI to display on the actual card frame, as you can see.
Making a memory game where you click a square it turns over an image and you match the two pretty simple. My issue is my images are not displaying and I am not sure why everything looks correct to me.
I want my function to return an array, with the array holding just the values of data that appear in good.
This is what should be returned:
{3, 5, 3, 2, 3, 3}
What is currently being returned:
{0, 3, 5, 3}
I didn't want to miss any numbers, so I decided to iterate through j for the "good" array, and then just i for the one that I was looking for matching numbers. Perhaps part of the problem is that if the condition is met, it goes to the next iteration of the loop. I'm not sure.
public class Arrays2 { public static void main(String args[]){ int [] data = {8, 3, 5, 3, 7, 2, 8, 3, 3 }; int [] good = {5, 2, 3, 2}; int [] result = f2(data, good); for (int i = 0; i < result.length; i++){
"A common memory matching game played by young children is to start with a deck of cards that contain identical pairs. For example, given six cards in the deck, two might be labeled
1, two might be labeled 2 and two might be labeled 3. The cards are shuffled and placed face down on the table.
The player then selects two cards that are face down, turns them face up, and if they match they are left face up. If the two cards do not match they are returned to their original position face down. The game continues in this fashion until all cards are face up.Write a program that plays the memory matching game. Use sixteen cards that are laid out in a 4x4 square and are labeled with pairs of numbers from 1 to 8. Your program should allow the player to specify the cards that she would like to select through a coordinate system.For example in the following layout:
All of the cards are face down except for the pair 8 which has been located at coordinates (1,1) and (2,3). To hide the cards that have been temporarily placed face up, output a large number of newlines to force the old board off the screen.Use 2D array for the arrangement of cards and another 2D array that indicates if a card is face up or face down.Or, a more elegant solution is to create a single 2D array where each element is an object that stores both the cards value and face.Write a function that shuffles the cards in the array by repeatedly selecting two cards at random and swapping them.
Note:To generate a random number x, where 0<= x <1, use x=Math.random();.For example, multiplying y six and converting to an integer results in an integer that is from 0 to 5."I have been thinking about the algorithm and design of the question for a few hours.
I am creating a simple Symptom Checker application. The problem I have is that I'm trying to retrieve user input (JTextField) by comma's using StringTokenizer which contacts the database for a result which matches the user's input (SELECT * FROM DIAGNOSIS WHERE ?, ?, ?) . It successfully finds the correct result however only in a particular format. Not different combinations....
for example, if I enter say within the JTextField: "tearful, nausea, lack of motivation" it will find the result successfully (as that is how it is formatted within the particular column (in the database table) i wish to display a result from) however, if i enter a different combination of these symptoms: "nausea, lack of motivation, tearful" - it will not find any result. I'm very unsure how to make it work regardless of what is inputted first, second or last.
Here is the code:
public void actionPerformed(ActionEvent e) { try { String abc = fieldsymp1.getText(); StringTokenizer str = new StringTokenizer(abc); while (str.hasMoreTokens()) { str.nextToken((", ")).trim();