Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • aricca/chessTrack
  • nicolas.furquez/chessTrack
2 results
Show changes
Commits on Source (50)
Showing
with 1126 additions and 590 deletions
......@@ -2,7 +2,8 @@
*~
# Directories #
#ProyectoAndroid/ChessTrack/bin
ProyectoAndroid/ChessTrack/bin/*
ProyectoAndroid/ChessTrack/gen/*
#java specific
*.class
......
GNU LESSER GENERAL PUBLIC LICENSE
Version 2.1, February 1999
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
[This is the first released version of the Lesser GPL. It also counts
as the successor of the GNU Library Public License, version 2, hence
the version number 2.1.]
Preamble
The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users.
This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below.
When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things.
To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it.
For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights.
We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library.
To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others.
Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license.
Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs.
When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library.
We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances.
For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License.
In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system.
Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library.
The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run.
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you".
A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables.
The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".)
"Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library.
Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does.
1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library.
You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions:
a) The modified work must itself be a software library.
b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change.
c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License.
d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful.
(For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.)
These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library.
In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License.
3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices.
Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy.
This option is useful when you wish to copy part of the code of the Library into a program that is not a library.
4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange.
If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code.
5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License.
However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables.
When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law.
If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.)
Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself.
6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications.
You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things:
a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.)
b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with.
c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution.
d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place.
e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy.
For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable.
It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute.
7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things:
a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above.
b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work.
8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance.
9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it.
10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License.
11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library.
If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice.
This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License.
12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License.
13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation.
14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally.
NO WARRANTY
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Libraries
If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License).
To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found.
one line to give the library's name and an idea of what it does.
Copyright (C) year name of author
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Also add information on how to contact you by electronic and paper mail.
You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in
the library `Frob' (a library for tweaking knobs) written
by James Random Hacker.
signature of Ty Coon, 1 April 1990
Ty Coon, President of Vice
That's all there is to it!
......@@ -37,9 +37,9 @@
android:minSdkVersion="9"
android:targetSdkVersion="10" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera" android:required="false"/>
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>
......
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="uy.edu.fing.chesstrack"
android:versionCode="1"
android:versionName="1.0" >
<!-- <application -->
<!-- android:allowBackup="true" -->
<!-- android:icon="@drawable/ic_launcher" -->
<!-- android:label="@string/app_name" -->
<!-- android:theme="@style/AppTheme" > -->
<!-- </application> -->
<application
android:allowBackup="true"
android:label="@string/app_name"
android:icon="@drawable/ic_launcher"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<activity android:name="ChessTrackActivity"
android:label="@string/app_name"
android:screenOrientation="landscape"
android:configChanges="keyboardHidden|orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<supports-screens android:resizeable="true"
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:anyDensity="true" />
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="10" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera" android:required="false"/>
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>
<uses-feature android:name="android.hardware.camera.front" android:required="false"/>
<uses-feature android:name="android.hardware.camera.front.autofocus" android:required="false"/>
</manifest>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:opencv="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="@+id/btn_calibrar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="calibrar" />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<org.opencv.android.JavaCameraView
android:layout_width="fill_parent"
......
package uy.edu.chesstrack.communication;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
public class Client extends Activity {
private Socket socket;
private static final int SERVERPORT = 5000;
private static final String SERVER_IP = "10.0.2.2";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.main);
new Thread(new ClientThread()).start();
}
public void onClick(View view) {
try {
// EditText et = (EditText) findViewById(R.id.EditText01);
// String str = et.getText().toString();
PrintWriter out = new PrintWriter(new BufferedWriter(
new OutputStreamWriter(socket.getOutputStream())),
true);
//out.println(str);
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
class ClientThread implements Runnable {
@Override
public void run() {
try {
InetAddress serverAddr = InetAddress.getByName(SERVER_IP);
socket = new Socket(serverAddr, SERVERPORT);
} catch (UnknownHostException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
}
\ No newline at end of file
package uy.edu.chesstrack.communication;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.widget.TextView;
public class Server {
private ServerSocket serverSocket;
Handler updateConversationHandler;
Thread serverThread = null;
private TextView text;
public static final int SERVERPORT = 6000;
public Server() {
updateConversationHandler = new Handler();
this.serverThread = new Thread(new ServerThread());
this.serverThread.start();
}
public void Stop() {
try {
serverSocket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
class ServerThread implements Runnable {
public void run() {
Socket socket = null;
try {
serverSocket = new ServerSocket(SERVERPORT);
} catch (IOException e) {
e.printStackTrace();
}
while (!Thread.currentThread().isInterrupted()) {
try {
socket = serverSocket.accept();
CommunicationThread commThread = new CommunicationThread(socket);
new Thread(commThread).start();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
class CommunicationThread implements Runnable {
private Socket clientSocket;
private BufferedReader input;
private BufferedWriter output;
public CommunicationThread(Socket clientSocket) {
this.clientSocket = clientSocket;
try {
this.input = new BufferedReader(new InputStreamReader(this.clientSocket.getInputStream()));
this.output = new BufferedWriter(new OutputStreamWriter(this.clientSocket.getOutputStream()));
String str = "AYLEN RICCA";
PrintWriter out = new PrintWriter(this.output);
out.println(str);
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
public void run() {
while (!Thread.currentThread().isInterrupted()) {
try {
String read = input.readLine();
updateConversationHandler.post(new updateUIThread(read));
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
class updateUIThread implements Runnable {
private String msg;
public updateUIThread(String str) {
this.msg = str;
}
@Override
public void run() {
text.setText(text.getText().toString()+"Client Says: "+ msg + "\n");
}
}
}
\ No newline at end of file
package uy.edu.fing.chesstrack;
import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.CameraBridgeViewBase;
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener;
import org.opencv.android.JavaCameraView;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader;
import org.opencv.core.Mat;
import uy.edu.fing.chesstrack.modulovision.Adquisicion;
import uy.edu.fing.chesstrack.modulovision.Calibracion;
import uy.edu.fing.chesstrack.modulovision.Manager;
import android.app.Activity;
import android.media.AudioManager;
import android.media.ToneGenerator;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.text.Editable;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
public class ChessTrackActivity extends Activity implements CvCameraViewListener {
public class ChessTrackActivity extends Activity implements
CvCameraViewListener {
private static final String TAG = "CHESSTRACK::Activity";
private static final String IPV4_REGEX = "^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$";
private static final String PORT_REGEX = "^(\\d{4,5})$";
// estados
private static final int IDLE = 0;
private static final int CALIBRAR = 1;
private static final int JUGAR = 2;
private CameraBridgeViewBase mOpenCvCameraView;
private CameraBridgeViewBase _mOpenCvCameraView;
// private JavaCameraView _mOpenCvCameraView;
private Adquisicion adq;
private Calibracion calibrar;
private Button btnCalibrar;
private Manager _manager;
private MenuItem _mItemCalibrar;
private MenuItem _mItemServer;
private int _estado;
//TODO es chancho pero ver luego
private Mat frame;
private boolean isUsed;
private boolean isCalibrada ;
private final BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(
this) {
private final BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS:
{
case LoaderCallbackInterface.SUCCESS: {
Log.i(TAG, "OpenCV loaded successfully");
mOpenCvCameraView.enableView();
} break;
default:
{
_mOpenCvCameraView.enableView();
}
break;
default: {
super.onManagerConnected(status);
} break;
}
break;
}
}
};
@Override
public void onResume()
{
public void onResume() {
super.onResume();
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_9, this, mLoaderCallback);
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_9, this,
mLoaderCallback);
}
@Override
public void onCreate(Bundle savedInstanceState) {
Log.i(TAG, "called onCreate");
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.chess_track_layout);
mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.chess_track_layout);
mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);
mOpenCvCameraView.setCvCameraViewListener(this);
try {
isUsed = false;
isCalibrada =false;
addListenerOnButton();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
_mOpenCvCameraView = (JavaCameraView) findViewById(R.id.chess_track_layout);
_mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);
_mOpenCvCameraView.setCvCameraViewListener(this);
_manager = Manager.getInstance();
}
public void addListenerOnButton() {
public void getServerIp() {
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Communication Setup");
alert.setMessage("Set server ip");
btnCalibrar = (Button) findViewById(R.id.btn_calibrar);
btnCalibrar.setOnClickListener(new OnClickListener() {
final EditText input = new EditText(this);
alert.setView(input);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(View arg0) {
isUsed = true;
if(frame!=null){
if (Calibracion.getInstance().calibrar(frame)){
isCalibrada = true;
ToneGenerator toneG = new ToneGenerator(AudioManager.STREAM_ALARM, 50);
toneG.startTone(ToneGenerator.TONE_CDMA_ALERT_CALL_GUARD, 200); // 200 is duration in ms
try {
adq = new Adquisicion();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else{
ToneGenerator toneG = new ToneGenerator(AudioManager.STREAM_ALARM, 50);
toneG.startTone(ToneGenerator.TONE_CDMA_ALERT_CALL_GUARD, 700); // 200 is duration in ms
}
public void onClick(DialogInterface dialog, int whichButton) {
Editable value = input.getText();
if (value == null || value.toString().equals("")
|| !value.toString().matches(IPV4_REGEX)) {
Log.i(TAG, "INPUT= not valid IP" + value.toString());
getServerIp();
} else {
Log.i(TAG, "INPUT=" + value.toString());
Log.i(TAG, "IP=" + value.toString());
getServerPort(value.toString());
}
isUsed = false;
}
});
alert.show();
}
public void getServerPort(final String ip) {
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Communication Setup");
alert.setMessage("Set server port");
final EditText input = new EditText(this);
alert.setView(input);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {
Editable value = input.getText();
Log.i(TAG, "INPUT=" + value.toString());
if (value == null || value.toString().equals("")
|| !value.toString().matches(PORT_REGEX)) {
Log.i(TAG, "INPUT= not valid PORT" + value.toString());
getServerPort(ip);
} else {
Log.i(TAG, "INPUT=" + value.toString());
int port = Integer.parseInt(value.toString());
Log.i(TAG, "PORT=" + port);
_manager.setConnection(ip, port);
}
}
});
alert.show();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
Log.i(TAG, "called onCreateOptionsMenu");
_mItemCalibrar = menu.add("Calibrar..");
_mItemServer = menu.add("Conectar Server");
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Log.i(TAG, "Menu Item selected " + item);
if (item == _mItemCalibrar) {
if (_estado == IDLE) {
_estado = CALIBRAR;
}
} else if (item == _mItemServer) {
getServerIp();
}
return true;
}
@Override
public void onPause()
{
public void onPause() {
super.onPause();
if (mOpenCvCameraView != null) {
mOpenCvCameraView.disableView();
if (_mOpenCvCameraView != null) {
_mOpenCvCameraView.disableView();
}
}
@Override
public void onDestroy() {
super.onDestroy();
if (mOpenCvCameraView != null) {
mOpenCvCameraView.disableView();
if (_mOpenCvCameraView != null) {
_mOpenCvCameraView.disableView();
}
if (_manager != null) {
_manager.destroy();
}
}
......@@ -140,22 +187,26 @@ public class ChessTrackActivity extends Activity implements CvCameraViewListener
public void onCameraViewStopped() {
}
@Override
public Mat onCameraFrame(Mat inputFrame) {
// TODO MANEJAR ESTADOS
if (!isUsed){
frame = inputFrame;
}
if(isCalibrada){
Log.i(TAG, "calibrada");
return adq.processFrame(inputFrame);
if (inputFrame != null) {
switch (_estado) {
case CALIBRAR:
Log.i(TAG, "calibrando...");
if (_manager.calibrar(inputFrame)) {
_estado = JUGAR;
} else {
_estado = IDLE;
}
break;
case JUGAR:
Log.i(TAG, "jugando...");
_manager.processFrame(inputFrame);
break;
case IDLE:
break;
}
}
return inputFrame;
}
}
package uy.edu.fing.chesstrack.ajedrez;
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.Size;
public class Logica {
private static final String TAG = "CHESSTRACK::Logica";
private Mat _tableroInicio;
private Mat _tableroAnterior;
public Logica() {
double[] vectorONES = { 1, 1, 1, 1, 1, 1, 1, 1 };
_tableroInicio = Mat.zeros(new Size(8, 8), CvType.CV_8UC1);
_tableroInicio.put(0, 0, vectorONES);
_tableroInicio.put(1, 0, vectorONES);
_tableroInicio.put(6, 0, vectorONES);
_tableroInicio.put(7, 0, vectorONES);
_tableroAnterior = _tableroInicio;
}
public Mat getTableroInicio() {
return _tableroInicio;
}
public boolean validarNuevoTablero(Mat actual) {
Mat result = new Mat(8, 8, CvType.CV_8UC1);
Core.absdiff(actual, _tableroAnterior, result);
if (Core.countNonZero(result) != 0) {
_tableroAnterior = actual;
}
return (Core.countNonZero(result) != 0);
}
public boolean validarTableroArmado(Mat nuevo) {
Mat result = new Mat(8, 8, CvType.CV_8UC1);
Core.absdiff(nuevo, _tableroInicio, result);
return (Core.countNonZero(result) == 0);
}
}
package uy.edu.fing.chesstrack.communication;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import android.util.Log;
public class Client {
private static final String TAG = "CLIENT";
private static Client _clientInstance;
private Socket serverSocket;
private int _serverPort = 5556;
private String _serverIp = "192.168.1.23";
// private BufferedReader input;
private DataOutputStream output;
protected Client() {
}
public static Client getInstance() {
if (_clientInstance == null) {
_clientInstance = new Client();
}
return _clientInstance;
}
public void EstablishConnection(String serverIp, int serverPort) {
Log.i(TAG, "init client-server communication");
this._serverIp = serverIp;
this._serverPort = serverPort;
try {
Log.i(TAG, "Server on " + this._serverIp + ":" + _serverPort);
InetAddress serverAddr = InetAddress.getByName(this._serverIp);
serverSocket = new Socket(serverAddr, _serverPort);
// get stream to send data
this.output = new DataOutputStream(
this.serverSocket.getOutputStream());
// get stream to receive data
// this.input = new BufferedReader(new
// InputStreamReader(this.serverSocket.getInputStream()));
} catch (IOException e) {
e.printStackTrace();
}
}
public void SendData(String msg) {
try {
Log.i(TAG, "sending=" + msg);
this.output.writeBytes(msg);
} catch (IOException e) {
e.printStackTrace();
}
}
/*
* public String ReceiveData() { try { String read = input.readLine();
* Log.i(TAG, "received="+ read); return read; } catch (IOException e) {
* e.printStackTrace(); return null; } }
*/
public void Stop() {
try {
// input.close();
output.close();
serverSocket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
package uy.edu.fing.chesstrack.modulomodelador;
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.Point;
import org.opencv.core.Rect;
import org.opencv.core.Scalar;
import org.opencv.core.Size;
import org.opencv.imgproc.Imgproc;
import uy.edu.fing.chesstrack.modulovision.Calibracion;
import android.util.Log;
public class Modelador {
private static final String TAG = "CHESSTRACK::Modelador";
private final int CANT_FILAS = 8;
// private final int CANT_SCAQUE = CANT_FILAS * CANT_FILAS;
private final int MIN_CANT_PIX_WHITE = 30;
private Mat tablero;
// se cuentan de arrib a abajo y de izquierda a derecha
private final Mat[][] escaques;
// private static Modelador instance;
public Modelador() {
tablero = Mat.zeros(new Size(8, 8), CvType.CV_8UC1);
escaques = new Mat[CANT_FILAS][CANT_FILAS];
}
public void dividirTablero(Mat inputFrame) {
Imgproc.cvtColor(inputFrame, inputFrame, Imgproc.COLOR_RGBA2GRAY, 4);
int largo = inputFrame.rows();
int ancho = inputFrame.cols();
// obtengo cuanto mide en ancho y largo un escaque
int largoEscaque = (int) Math.floor(largo / (CANT_FILAS + 2));// +2
// porque
// se
// toma
// un
// escaque
// mas
// de
// borde
int anchoEscaque = (int) Math.floor(ancho / (CANT_FILAS + 2));
Log.i(TAG, "largoEscaque= " + largoEscaque);
Log.i(TAG, "anchoEscaque= " + anchoEscaque);
for (int i = 0; i < CANT_FILAS; i++) {
for (int j = 0; j < CANT_FILAS; j++) {
int rowStart = (int) Math.floor(largoEscaque) + i
* largoEscaque + 4;
int rowEnd = (int) Math.floor(largoEscaque) + i * largoEscaque
+ largoEscaque - 4;
int colStart = (int) Math.floor(anchoEscaque) + j
* anchoEscaque + 4;
int colEnd = (int) Math.floor(anchoEscaque) + j * anchoEscaque
+ anchoEscaque - 4;
escaques[i][j] = inputFrame.submat(colStart, colEnd, rowStart,
rowEnd);
}
}
}
private int getHayFichaEnEscaque(int i, int j) {
int ret = 0;
Mat mIntermediateMat = new Mat();
Imgproc.Sobel(escaques[i][j], mIntermediateMat, CvType.CV_8U, 1, 1);
Core.convertScaleAbs(mIntermediateMat, mIntermediateMat, 10, 0);
Imgproc.threshold(mIntermediateMat, mIntermediateMat, 70, 255,
Imgproc.THRESH_BINARY);
// int cant_pix = mIntermediateMat.cols() * mIntermediateMat.rows();
int cant_pix_white = Core.countNonZero(mIntermediateMat);
if (cant_pix_white > (MIN_CANT_PIX_WHITE)) {
ret = 1;
}
return ret;
}
public Mat getMatrizFichas(Mat frame) {
dividirTablero(frame);
tablero = Mat.zeros(new Size(8, 8), CvType.CV_8UC1);
for (int i = 0; i < CANT_FILAS; i++) {
for (int j = 0; j < CANT_FILAS; j++) {
tablero.put(i, j, getHayFichaEnEscaque(i, j));
}
}
return tablero.t();
}
public Mat dibujarEscaque() {
Mat tmp = Mat.ones(Calibracion.getInstance().get_sizeFrame(),
CvType.CV_8UC4);
Mat subm; // tmp.submat(new Rect(new Point(0,0)
// ,escaques[i][j].size()));
// escaques[i][j].copyTo(subm);
int pos_x = 0;
int pos_y = 0;
for (int i = 0; i < CANT_FILAS; i++) {
for (int j = 0; j < CANT_FILAS; j++) {
pos_x = (int) (escaques[i][j].size().width * i);
pos_y = (int) (escaques[i][j].size().height * j);
subm = tmp.submat(new Rect(new Point(pos_x, pos_y),
escaques[i][j].size()));
escaques[i][j].copyTo(subm);
Core.putText(tmp,
Integer.toString(i) + "-" + Integer.toString(j),
new Point(pos_x + 1, pos_y + 1),
Core.FONT_HERSHEY_SIMPLEX, 0.3, new Scalar(255, 0, 0));
}
}
return tmp;
}
public Mat dibujarEscaquesCanny() {
Mat tmp = Mat.zeros(Calibracion.getInstance().get_sizeFrame(),
CvType.CV_8UC4);
Mat subm; // tmp.submat(new Rect(new Point(0,0)
// ,escaques[i][j].size()));
// escaques[i][j].copyTo(subm);
Mat mIntermediateMat = new Mat();
int pos_x = 0;
int pos_y = 0;
for (int i = 0; i < CANT_FILAS; i++) {
for (int j = 0; j < CANT_FILAS; j++) {
pos_x = (int) (escaques[i][j].size().width * i);
pos_y = (int) (escaques[i][j].size().height * j);
subm = tmp.submat(new Rect(new Point(pos_x, pos_y),
escaques[i][j].size()));
Imgproc.Canny(escaques[i][j], mIntermediateMat, 80, 90);
Imgproc.cvtColor(mIntermediateMat, subm,
Imgproc.COLOR_GRAY2RGBA, 4);
escaques[i][j].copyTo(subm);
Core.putText(tmp,
Integer.toString(i) + "-" + Integer.toString(j),
new Point(pos_x + 1, pos_y + 1),
Core.FONT_HERSHEY_SIMPLEX, 0.3, new Scalar(255, 0, 0));
}
}
return tmp;
}
public Mat dibujarEscaquesSobel(int version) {
Mat tmp = Mat.zeros(Calibracion.getRectROI().size(), CvType.CV_8UC4);
Mat subm; // tmp.submat(new Rect(new Point(0,0)
// ,escaques[i][j].size()));
// escaques[i][j].copyTo(subm);
Mat mIntermediateMat = new Mat();
int pos_x = 0;
int pos_y = 0;
Log.i(TAG, "cant_pix_INI");
for (int i = 0; i < CANT_FILAS; i++) {
for (int j = 0; j < CANT_FILAS; j++) {
pos_x = (int) (escaques[i][j].size().width * i);
pos_y = (int) (escaques[i][j].size().height * j);
subm = tmp.submat(new Rect(new Point(pos_x, pos_y),
escaques[i][j].size()));
// Imgproc.cvtColor(escaques[i][j] ,mIntermediateMat,
// Imgproc.COLOR_RGBA2GRAY,4);
Imgproc.Sobel(escaques[i][j], mIntermediateMat, CvType.CV_8U,
1, 1);
Core.convertScaleAbs(mIntermediateMat, mIntermediateMat, 10, 0);
Imgproc.threshold(mIntermediateMat, mIntermediateMat, 70, 255,
Imgproc.THRESH_BINARY);
Imgproc.erode(mIntermediateMat, mIntermediateMat, Imgproc
.getStructuringElement(Imgproc.MORPH_RECT, new Size(1,
1)));
Imgproc.dilate(mIntermediateMat, mIntermediateMat, Imgproc
.getStructuringElement(Imgproc.MORPH_RECT, new Size(1,
1)));
int cant_pix = mIntermediateMat.cols()
* mIntermediateMat.rows();
int cant_pix_white = Core.countNonZero(mIntermediateMat);
Log.i(TAG, "cant_pix=" + cant_pix);
Log.i(TAG, "cant_pix_white=" + cant_pix_white);
switch (version) {
case 1:
if (cant_pix_white > (MIN_CANT_PIX_WHITE)) {
Imgproc.cvtColor(mIntermediateMat, subm,
Imgproc.COLOR_GRAY2RGBA, 4);
} else {
Imgproc.cvtColor(escaques[i][j], subm,
Imgproc.COLOR_GRAY2RGBA, 4);
}
break;
case 2:
if (cant_pix_white > (MIN_CANT_PIX_WHITE)) {
Log.i(TAG, "NUEVA FICHA" + (i + 1) + "-" + (j + 1));
}
Imgproc.cvtColor(mIntermediateMat, subm,
Imgproc.COLOR_GRAY2RGBA, 4);
break;
default:
Imgproc.cvtColor(escaques[i][j], subm,
Imgproc.COLOR_GRAY2RGBA, 4);
break;
}
}
}
Log.i(TAG, "cant_pix_FIN");
return tmp;
}
}
package uy.edu.fing.chesstrack.modulovision;
import java.util.ArrayList;
import java.util.List;
......@@ -9,25 +7,20 @@ import org.opencv.core.Mat;
import uy.edu.fing.chesstrack.modulovision.imgproc.Homografia;
import uy.edu.fing.chesstrack.modulovision.imgproc.ImgProcInterface;
import uy.edu.fing.chesstrack.modulovision.imgproc.SustraccionDeFondo;
import android.util.Log;
public class Adquisicion {
List<ImgProcInterface> listProc;
private static final String TAG = "CHESSTRACK::Adquisicion";
List<ImgProcInterface> _listProc;
public Adquisicion() throws Exception {
super();
Log.i(TAG, "Cargado....");
listProc = new ArrayList<ImgProcInterface>();
_listProc = new ArrayList<ImgProcInterface>();
listProc.add( new Homografia());
//listProc.add( new EcualizarImagen());
listProc.add( new SustraccionDeFondo());
_listProc.add(new Homografia());
//_listProc.add(new EcualizarImagen());
}
/**
......@@ -39,12 +32,10 @@ public class Adquisicion {
*/
public synchronized Mat processFrame(Mat inputPicture) {
Log.i(TAG, "processFrame inicia");
Mat salida = inputPicture;
Mat prevImg = inputPicture;
for (ImgProcInterface proc: listProc){
prevImg = proc.procesarImagen(prevImg);
Mat tempImg = inputPicture;
for (ImgProcInterface proc: _listProc){
tempImg = proc.procesarImagen(tempImg);
}
return prevImg;
return tempImg;
}
}
......@@ -8,76 +8,64 @@ import org.opencv.core.Size;
import android.util.Log;
public class Calibracion {
private Mat imagenCalibrada;
private Mat imagenOriginal;
private MatOfPoint2f vertices;
public class Calibracion {
private static final String TAG = "CHESSTRACK::Calibracion";
private static Rect rectPOI = null;
private static Calibracion instance;
private Size _sizeFrame = null;
private MatOfPoint2f _vertices = null;
private static Rect _rectROI = null;
private static Calibracion _instance;
protected Calibracion(){
protected Calibracion() {
}
public static Calibracion getInstance(){
if(instance == null){
instance = new Calibracion();
public static Calibracion getInstance() {
if (_instance == null) {
_instance = new Calibracion();
}
return instance;
return _instance;
}
public boolean calibrar(Mat img){
public boolean calibrar(Mat img) {
Log.i(TAG, "INI calibrando");
boolean OK = false;
imagenOriginal = img;
imagenCalibrada = img;
Size patternSize = new Size(7,7);
Size patternSize = new Size(7, 7);
MatOfPoint2f corners = new MatOfPoint2f();
boolean ret = Calib3d.findChessboardCorners(imagenOriginal, patternSize, corners);
if (ret){
boolean ret = Calib3d.findChessboardCorners(img, patternSize, corners);
if (ret) {
Log.i(TAG, "Encontro = " + corners.total());
Log.i(TAG, "Encontro = " + corners.size().toString());
Calib3d.drawChessboardCorners(imagenCalibrada, patternSize, corners, ret);
vertices = corners;
// Calib3d.drawChessboardCorners(img, patternSize, corners, ret);
// only for debug
_vertices = corners;
_sizeFrame = img.size();
}
OK = ret;
Log.i(TAG, "FIN calibrando = " + ret);
return OK;
return ret;
}
public Mat getImagenCalibrada() {
return imagenCalibrada;
public Size get_sizeFrame() {
return _sizeFrame;
}
public void setImagenCalibrada(Mat imagenCalibrada) {
this.imagenCalibrada = imagenCalibrada;
public void set_sizeFrame(Size _sizeFrame) {
this._sizeFrame = _sizeFrame;
}
public MatOfPoint2f getVertices() {
return vertices;
return _vertices;
}
public void setVertices(MatOfPoint2f vertices) {
this.vertices = vertices;
this._vertices = vertices;
}
public static Rect getRectPOI() {
return rectPOI;
public static Rect getRectROI() {
return _rectROI;
}
public static void setRectPOI(Rect rectPOI) {
Calibracion.rectPOI = rectPOI;
public static void setRectROI(Rect rectROI) {
Calibracion._rectROI = rectROI;
}
}
package uy.edu.fing.chesstrack.modulovision;
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.Scalar;
import org.opencv.core.Size;
import org.opencv.imgproc.Imgproc;
import org.opencv.video.BackgroundSubtractorMOG2;
import android.util.Log;
public class DetectorOclusion {
private static final String TAG = "CHESSTRACK::BackgroundSupress";
private static final int OCLUSION = 0;
private static final int ESTABLE = 1;
private static final int TRANSICION = 2;
private static final int ENVIAR_TABLERO = 3;
private static final int START = -1;
private final Mat _fgMaskMOG2;
private Mat _resultado;
private BackgroundSubtractorMOG2 _pMOG2;
private final Mat _morphKernel;
private int _estadoANTERIOR;
private int _estadoACTUAL;
public DetectorOclusion() {
super();
Log.i(TAG, "constructor INI");
_morphKernel = Imgproc.getStructuringElement(Imgproc.MORPH_RECT,
new Size(3, 3));
_fgMaskMOG2 = new Mat(4, 1, CvType.CV_8UC1);
_pMOG2 = new BackgroundSubtractorMOG2();
_estadoACTUAL = START;
_resultado = new Mat();
Log.i(TAG, "constructor FIN");
}
public Mat get_resultado() {
return _resultado;
}
public void set_resultado(Mat _resultado) {
this._resultado = _resultado;
}
public boolean hayNuevoTableroValido(Mat inputFrame) {
/*
* if (_estadoACTUAL == START){ _pMOG2 = new BackgroundSubtractorMOG2();
* // MOG2 approach }
*/
Log.i(TAG, "Procesar!");
Log.i(TAG, "Region SIZE=" + inputFrame.size());
_pMOG2.apply(inputFrame, _fgMaskMOG2);
Imgproc.erode(_fgMaskMOG2, _fgMaskMOG2, _morphKernel);
Log.i(TAG, "Apply erode");
Imgproc.threshold(_fgMaskMOG2, _fgMaskMOG2, 200, 255,
Imgproc.THRESH_BINARY);
Log.i(TAG, "Apply threshold");
// Imgproc.dilate(_fgMaskMOG2, _fgMaskMOG2, _morphKernel);
// Log.i(TAG, "Apply dilate");
Scalar suma = Core.sumElems(_fgMaskMOG2);
Log.i(TAG, "SUMA = " + suma);
_estadoANTERIOR = _estadoACTUAL;
if (suma.val[0] > 1250000) {
Log.i(TAG, "VEO MANO !!!");
_estadoACTUAL = OCLUSION;
/*
* Core.putText(_fgMaskMOG2, "MANO !!!", new Point(20, 20),
* Core.FONT_HERSHEY_SIMPLEX, 0.8, new Scalar(255, 255, 0));
*/
} else {
if (_estadoANTERIOR == OCLUSION) {
/*
* Core.putText(_fgMaskMOG2, "TRANSI !!!", new Point(20, 20),
* Core.FONT_HERSHEY_SIMPLEX, 0.8, new Scalar(255, 255, 0));
*/
Log.i(TAG, "VEO TRANSICION !!!");
_estadoACTUAL = TRANSICION;
}
if (_estadoANTERIOR == TRANSICION) {
/*
* Core.putText(_fgMaskMOG2, "ESTABLE !!!", new Point(20, 20),
* Core.FONT_HERSHEY_SIMPLEX, 0.8, new Scalar(255, 255, 0));
*/
_estadoACTUAL = ENVIAR_TABLERO;
_pMOG2 = new BackgroundSubtractorMOG2(); // MOG2 approach
Log.i(TAG, "VEO ENVIAR !!!");
}
if (_estadoANTERIOR == ENVIAR_TABLERO) {
_estadoACTUAL = ESTABLE;
Log.i(TAG, "VEO ESTABLE !!!");
}
}
Log.i(TAG, "END");
Imgproc.cvtColor(_fgMaskMOG2, _resultado, Imgproc.COLOR_GRAY2RGBA, 4);
return (_estadoACTUAL == ENVIAR_TABLERO);
}
}
/*
* double maxArea = 0; MatOfPoint largestContour = null;
* Imgproc.findContours(_fgMaskMOG2, contours, new Mat(), Imgproc.RETR_LIST,
* Imgproc.CHAIN_APPROX_TC89_L1); for (MatOfPoint contour : contours) { double
* area = Imgproc.contourArea(contour); if (area > maxArea) { maxArea = area;
* largestContour = contour; } } Log.i(TAG, "ESTABLE !!!" + maxArea); if
* ((largestContour != null) && (maxArea > 10000)){ Log.i(TAG, "MANO !!!" +
* maxArea); Rect boundingRect = Imgproc.boundingRect(largestContour);
* ToneGenerator toneG = new ToneGenerator(AudioManager.STREAM_ALARM, 50);
* toneG.startTone(ToneGenerator.TONE_CDMA_ALERT_CALL_GUARD, 200); // 200 is
* duration in ms }
*/
/*
* Imgproc.findContours(_fgMaskMOG2, contours, new Mat(), Imgproc.RETR_LIST,
* Imgproc.CHAIN_APPROX_NONE);
*
* for(int idx = 0; idx < contours.size(); idx++) { double area =
* Imgproc.contourArea(contours.get(idx)); Log.i(TAG, "CONTOUR = AREA: " +
* area); if ((area > 15000) && (area < 70000)){ Log.i(TAG, "DRAW !!! : " +
* area); Scalar color = new Scalar(255,127,127); Rect r =
* Imgproc.boundingRect(contours.get(idx)); Log.i(TAG,
* "3 at backgroundS "+(_fgMaskMOG2.type() == CvType.CV_8UC1));
* Core.rectangle(_fgMaskMOG2, r.tl(), r.br(), color, 2, 8, 0);
* //Imgproc.drawContours(_fgMaskMOG2, contours, idx, color); } }
*
* contours.clear();
*/
\ No newline at end of file
package uy.edu.fing.chesstrack.modulovision;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import uy.edu.fing.chesstrack.ajedrez.Logica;
import uy.edu.fing.chesstrack.communication.Client;
import uy.edu.fing.chesstrack.modulomodelador.Modelador;
import android.media.AudioManager;
import android.media.ToneGenerator;
import android.util.Log;
public class Manager {
private static final String TAG = "CHESSTRACK::MANAGER";
private static Manager _instance;
private static final int ARMANDO_TABLERO = 0;
private static final int JUGANDO = 1;
private static final int OK = 1;
private static final int NOT = 0;
private static final String WELCOME_MSG = ""
+ "--------------------------------------------------------------------------\n"
+ " .:: CHESSTRACK ::. seguimiento de una partida de Ajedrez\n"
+ "\n"
+ " TImag 2014\n"
+ " Nicolas Furquez - Aylen Ricca\n"
+ "--------------------------------------------------------------------------\n";
private static int _estado;
private static int _salida;
private static Adquisicion _adquisicion;
private static Client _client;
private static DetectorOclusion _detectorOclusion;
private static Modelador _modelador;
private static Logica _logica;
private final boolean _debug;
private int _cantJugada;
protected Manager() {
_estado = ARMANDO_TABLERO;
_salida = NOT;
_adquisicion = null;
_client = null;
_debug = false;
_cantJugada = 0;
}
public static Manager getInstance() {
if (_instance == null) {
_instance = new Manager();
}
return _instance;
}
public static int get_estado() {
return _estado;
}
public static void set_estado(int _estado) {
Manager._estado = _estado;
}
public void setConnection(String ip, int port) {
Log.i(TAG, "Setting connection");
_client = Client.getInstance();
_client.EstablishConnection(ip, port);
_client.SendData(WELCOME_MSG);
_salida = OK;
}
public boolean calibrar(Mat frame) {
Log.i(TAG, "Calibrando");
if (Calibracion.getInstance().calibrar(frame)) {
ToneGenerator toneG = new ToneGenerator(AudioManager.STREAM_ALARM,
50);
toneG.startTone(ToneGenerator.TONE_CDMA_ALERT_CALL_GUARD, 200); // ms
if (_salida == OK) {
_client.SendData("FIN calibrar\n . . . armando tablero!\n");
}
try {
_adquisicion = new Adquisicion();
_modelador = new Modelador();
_logica = new Logica();
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
Log.i(TAG, "No calibrado");
ToneGenerator toneG = new ToneGenerator(AudioManager.STREAM_ALARM, 50);
toneG.startTone(ToneGenerator.TONE_CDMA_ALERT_CALL_GUARD, 700);
return false;
}
public void iniciarJuego() {
_estado = JUGANDO;
// beep
_detectorOclusion = new DetectorOclusion();
ToneGenerator toneG = new ToneGenerator(AudioManager.STREAM_ALARM, 50);
toneG.startTone(ToneGenerator.TONE_CDMA_ALERT_CALL_GUARD, 200); // ms
if (_salida == OK) {
Mat tableroInicio = _logica.getTableroInicio();
_client.SendData("TableroINICIO!\n");
_client.SendData(" ".concat(tableroInicio.dump().concat("\n")));
}
}
public Mat processFrame(Mat inputFrame) {
Log.i(TAG, "Acondicionamiento");
Mat region = _adquisicion.processFrame(inputFrame);
Log.i(TAG, "TYPE=" + (inputFrame.type() == CvType.CV_8UC4));
Log.i(TAG, "CHANNEL=" + (inputFrame.channels() == 4));
switch (_estado) {
case ARMANDO_TABLERO:
Log.i(TAG, "Armando Tablero");
Mat nuevo = _modelador.getMatrizFichas(region);
if (_logica.validarTableroArmado(nuevo)) {
iniciarJuego();
}
break;
case JUGANDO:
Log.i(TAG, "Jugando");
if (_detectorOclusion.hayNuevoTableroValido(region)) {
Log.i(TAG, "Tablero Valido");
// llamar al modelador
Mat aux = _modelador.getMatrizFichas(region);
// Log.i(TAG, "MATRIZ=" + aux.dump());
// region = _modelador.dibujarEscaquesSobel(2);
if (_logica.validarNuevoTablero(aux)) {
if (_salida == OK) {
_client.SendData("Nuevo Tablero Valido = ["
+ String.valueOf(_cantJugada) + "]\n");
_cantJugada++;
_client.SendData(" ".concat(aux.dump().concat("\n")));
}
}
}
break;
}
if (_debug) {
Log.i(TAG, "DEBUG");
Mat tmp = Mat.zeros(inputFrame.size(), CvType.CV_8UC4);
Mat matTMP = tmp.submat(Calibracion.getRectROI());
region.copyTo(matTMP);
return tmp;
}
return inputFrame;
}
public void destroy() {
if (_client != null) {
_client.Stop();
}
}
}
package uy.edu.fing.chesstrack.modulovision.imgproc;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Vector;
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.MatOfPoint;
import org.opencv.core.Point;
import org.opencv.core.Rect;
import org.opencv.core.Scalar;
import org.opencv.core.Size;
import org.opencv.video.BackgroundSubtractorMOG;
import org.opencv.video.BackgroundSubtractorMOG2;
import org.opencv.imgproc.*;
import android.graphics.SumPathEffect;
import android.media.AudioManager;
import android.media.ToneGenerator;
import android.util.Log;
public class BackgroundSupress implements ImgProcInterface {
private static final String TAG = "CHESSTRACK::BackgroundSupress";
private final Mat fgMaskMOG;
private final Mat fgMaskMOG2;
private final Mat morphKernel;
private final BackgroundSubtractorMOG pMOG;
private final BackgroundSubtractorMOG2 pMOG2;
private final List<MatOfPoint> contours;
public BackgroundSupress() {
super();
morphKernel = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(3,3));
fgMaskMOG = new Mat(4,1,CvType.CV_8UC1);
fgMaskMOG2 = new Mat(4,1,CvType.CV_8UC1);
pMOG = new BackgroundSubtractorMOG(); //MOG approach
pMOG2 = new BackgroundSubtractorMOG2(); //MOG approach
Log.i(TAG, "at background supress constructor");
contours = new ArrayList<MatOfPoint>();
}
@Override
public Mat procesarImagen(Mat inputFrame) {
Log.i(TAG, "BackgroundS ");
Mat copy = new Mat(inputFrame.size(),CvType.CV_8UC3);
inputFrame.convertTo(copy, CvType.CV_8UC3);
Imgproc.cvtColor(inputFrame, copy, Imgproc.COLOR_BGRA2BGR);
pMOG.apply(copy, fgMaskMOG);
pMOG2.apply(copy, fgMaskMOG2,0);
Log.i(TAG, "Apply pMOG");
Imgproc.erode(fgMaskMOG2, fgMaskMOG2, morphKernel);
Log.i(TAG, "Apply erode");
Imgproc.threshold(fgMaskMOG2, fgMaskMOG2, 200, 255, Imgproc.THRESH_BINARY);
Log.i(TAG, "Apply threshold");
Imgproc.dilate(fgMaskMOG2, fgMaskMOG2, morphKernel);
Log.i(TAG, "Apply dilate");
Scalar suma = Core.sumElems(fgMaskMOG2);
Log.i(TAG, "SUMA = " + suma);
/*double maxArea = 0;
MatOfPoint largestContour = null;
Imgproc.findContours(fgMaskMOG2, contours, new Mat(), Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_TC89_L1);
for (MatOfPoint contour : contours) {
double area = Imgproc.contourArea(contour);
if (area > maxArea) {
maxArea = area;
largestContour = contour;
}
}
Log.i(TAG, "ESTABLE !!!" + maxArea);
if ((largestContour != null) && (maxArea > 10000)){
Log.i(TAG, "MANO !!!" + maxArea);
Rect boundingRect = Imgproc.boundingRect(largestContour);
ToneGenerator toneG = new ToneGenerator(AudioManager.STREAM_ALARM, 50);
toneG.startTone(ToneGenerator.TONE_CDMA_ALERT_CALL_GUARD, 200); // 200 is duration in ms
}*/
if (suma.val[0] > 100000){
Log.i(TAG, "MANO !!!");
Core.putText(fgMaskMOG2, "MANO !!!", new Point(50, 50),Core.FONT_HERSHEY_SIMPLEX, 0.8 , new Scalar(255,255,0));
// ToneGenerator toneG = new ToneGenerator(AudioManager.STREAM_ALARM, 50);
// toneG.startTone(ToneGenerator.TONE_CDMA_ALERT_CALL_GUARD, 200); // 200 is duration in ms
} else {
Log.i(TAG, "ESTABLE !!!");
Core.putText(fgMaskMOG2, "ESTABLE !!!", new Point(50, 50),Core.FONT_HERSHEY_SIMPLEX, 0.5 , new Scalar(255,255,0));
}
/*Imgproc.findContours(fgMaskMOG2, contours, new Mat(), Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_NONE);
for(int idx = 0; idx < contours.size(); idx++)
{
double area = Imgproc.contourArea(contours.get(idx));
Log.i(TAG, "CONTOUR = AREA: " + area);
if ((area > 15000) && (area < 70000)){
Log.i(TAG, "DRAW !!! : " + area);
Scalar color = new Scalar(255,127,127);
Rect r = Imgproc.boundingRect(contours.get(idx));
Log.i(TAG, "3 at backgroundS "+(fgMaskMOG2.type() == CvType.CV_8UC1));
Core.rectangle(fgMaskMOG2, r.tl(), r.br(), color, 2, 8, 0);
//Imgproc.drawContours(fgMaskMOG2, contours, idx, color);
}
}
contours.clear();*/
Log.i(TAG, "END Background Sss");
return fgMaskMOG2;
}
}
......@@ -3,17 +3,32 @@ package uy.edu.fing.chesstrack.modulovision.imgproc;
import org.opencv.core.Mat;
import org.opencv.imgproc.Imgproc;
import android.util.Log;
public class EcualizarImagen implements ImgProcInterface {
private static final String TAG = "CHESSTRACK::Ecualizar";
@Override
public Mat procesarImagen(Mat inputFrame) {
// TODO Auto-generated method stub
//cvEqualizeHist(src,dest)
Mat viewGray = new Mat();
Imgproc.cvtColor(inputFrame, viewGray, Imgproc.COLOR_BGR2GRAY);
Imgproc.equalizeHist(viewGray,viewGray);
//Imgproc.equalizeHist(inputFrame,inputFrame);
return viewGray;
}
//List<Mat> channels = new ArrayList<Mat>();
Mat img_hist_equalized = new Mat();
Log.i(TAG, "processing Frame - INI");
Imgproc.cvtColor(inputFrame, img_hist_equalized, Imgproc.COLOR_BGR2GRAY);
Imgproc.equalizeHist(img_hist_equalized, img_hist_equalized);
Imgproc.cvtColor(img_hist_equalized, inputFrame, Imgproc.COLOR_GRAY2BGR);
/*// ecualizar en cada canal
Core.split(inputFrame, channels); // split the image into channels
//Imgproc.equalizeHist(channels.get(0), channels.get(0));
Imgproc.equalizeHist(channels.get(1), channels.get(1));
//Imgproc.equalizeHist(channels.get(2), channels.get(2));
Core.merge(channels, inputFrame);
*/
Log.i(TAG, "processing Frame - FIN");
return img_hist_equalized;
}
}
......@@ -5,6 +5,7 @@ import org.opencv.core.Mat;
import org.opencv.core.MatOfPoint2f;
import org.opencv.core.Point;
import org.opencv.core.Rect;
import org.opencv.core.Size;
import org.opencv.imgproc.Imgproc;
import uy.edu.fing.chesstrack.modulovision.Calibracion;
......@@ -13,54 +14,105 @@ import android.util.Log;
public class Homografia implements ImgProcInterface {
private static final String TAG = "CHESSTRACK::Homografia";
private final Mat matrizTransformada;
private final Rect rectPOI;
private final Mat _matrizTransformada;
private final Rect _rectROI;
private int _media;
private int _offset;
public Homografia() throws Exception {
super();
MatOfPoint2f vertices = Calibracion.getInstance().getVertices();
if (vertices != null){
Mat src = new Mat(4,1,CvType.CV_32FC2);
Mat dst = new Mat(4,1,CvType.CV_32FC2);
Point p1,p2,p3,p4;
p1 = vertices.toList().get(0);
p2 = vertices.toList().get(6);
p3 = vertices.toList().get(42);
p4 = vertices.toList().get(48);
double d17 = Math.sqrt(Math.pow((p1.x- p2.x),2) + Math.pow((p1.y- p2.y),2));
double d749 = Math.sqrt(Math.pow((p2.x- p4.x),2) + Math.pow((p2.y- p4.y),2));
double d143 = Math.sqrt(Math.pow((p1.x- p3.x),2) + Math.pow((p1.y- p3.y),2));
double d4349 = Math.sqrt(Math.pow((p3.x- p4.x),2) + Math.pow((p3.y- p4.y),2));
int media = (int) Math.floor( Math.round((d17+d749+d143+d4349)/4));
int offset = 2*(media/7);
src.put(0,0 ,(int)p1.x,(int)p1.y, (int)p2.x,(int)p2.y, (int)p3.x,(int)p3.y, (int)p4.x,(int)p4.y);
dst.put(0,0, offset,offset ,offset+media,offset , offset,offset+media , offset+media,offset+media );
Log.i(TAG, "offset= " + offset);
Log.i(TAG, "media = " + media);
// EL offset es casi el tamaño de una celda
rectPOI = new Rect(new Point(0,0), new Point(2*offset+media,2*offset+media));
Calibracion.getInstance().setRectPOI(rectPOI);
matrizTransformada = Imgproc.getPerspectiveTransform(src,dst);
}else{
Point p1, p2, p3, p4;
Point[] ret = getBestPoints(vertices, Calibracion.getInstance().get_sizeFrame());
Log.i(TAG, "Best Points= " + ret.toString());
p1 = ret[0];
p2 = ret[1];
p3 = ret[2];
p4 = ret[3];
// se obtienen las distancias de cada una de las aristas que determinan los vertices
// internos mas externos y se determina el promedio de esa medida
double d12 = Math.sqrt(Math.pow((p1.x- p2.x),2) + Math.pow((p1.y- p2.y),2));
double d23 = Math.sqrt(Math.pow((p2.x- p3.x),2) + Math.pow((p2.y- p3.y),2));
double d34 = Math.sqrt(Math.pow((p3.x- p4.x),2) + Math.pow((p3.y- p4.y),2));
double d14 = Math.sqrt(Math.pow((p4.x- p1.x),2) + Math.pow((p4.y- p1.y),2));
_media = (int) Math.floor( Math.round((d12+d23+d34+d14)/4));
// El offset es el tamaño de dos celdas (para abarcar el primer casillero y dejar un borde al tablero
_offset = 2*(_media/6);
Log.i(TAG, "media= " + _media);
Log.i(TAG, "offset= " + _offset);
src.put(0,0, (int)p1.x,(int)p1.y, (int)p2.x,(int)p2.y, (int)p3.x,(int)p3.y, (int)p4.x,(int)p4.y);
dst.put(0,0, _offset,_offset, _offset+_media,_offset, _offset+_media,_offset+_media, _offset,_offset+_media );
_rectROI = new Rect(new Point(0,0), new Point(2*_offset+_media,2*_offset+_media));
Calibracion.getInstance();
Calibracion.setRectROI(_rectROI);
Log.i(TAG, "rectROI size= " + _rectROI.size());
_matrizTransformada = Imgproc.getPerspectiveTransform(src,dst);
} else {
throw new Exception(TAG + "No se han calculado los vertices");
}
}
/**
* Hace homografia y recorta la imagen
*/
@Override
public Mat procesarImagen(Mat inputFrame) {
Log.i(TAG, "processing Frame - INI");
double x = inputFrame.size().width;
double y = inputFrame.size().height;
if (x < _rectROI.size().width){
x = _rectROI.size().width;
}
if (y < _rectROI.size().height){
y = _rectROI.size().height;
}
Mat aux = new Mat();
Imgproc.warpPerspective(inputFrame,inputFrame, matrizTransformada, inputFrame.size());
Mat subMat = inputFrame.submat(rectPOI);
Mat tmp = Mat.zeros(inputFrame.size(), CvType.CV_8UC4);
Mat matTMP = tmp.submat(rectPOI);
subMat.copyTo(matTMP);
return tmp;
// hace la homografia con la matriz calculada en un ppio
Imgproc.warpPerspective(inputFrame,aux, _matrizTransformada, new Size(x,y));
Mat tmp = Mat.zeros(_rectROI.size(), CvType.CV_8UC4);
(aux.submat(_rectROI)).copyTo(tmp);
Log.i(TAG, "processing Frame - FIN");
return tmp;
}
private Point[] getBestPoints(MatOfPoint2f vertices, Size tamanio){
double d, best_dist;
Point[] ret = new Point[4];
Point[] vect = new Point[4];
vect[0] = new Point(0,0);
vect[1] = new Point(tamanio.width,0);
vect[2] = new Point(tamanio.width,tamanio.height);
vect[3] = new Point(0,tamanio.height);
for (int i = 0; i < 4; i++){
Point aux = vect[i];
best_dist = Double.MAX_VALUE;
for(Point pt : vertices.toList()){
d = Math.sqrt(Math.pow((pt.x- aux.x),2) + Math.pow((pt.y- aux.y),2));
if (d < best_dist){
best_dist = d;
ret[i] = pt;
}
}
}
return ret;
}
}
package uy.edu.fing.chesstrack.modulovision.imgproc;
import org.opencv.core.Mat;
import org.opencv.imgproc.Imgproc;
import org.opencv.video.BackgroundSubtractorMOG2;
public class SustraccionDeFondo implements ImgProcInterface {
private Mat fMaskMOG = null;
private final BackgroundSubtractorMOG2 pMOG;
private static final String TAG = "CHESSTRACK::SustraccionDeFondo";
public SustraccionDeFondo(){
pMOG = new BackgroundSubtractorMOG2();
//fMaskMOG = new Mat();
}
@Override
public Mat procesarImagen(Mat inputFrame) {
Imgproc.cvtColor(inputFrame, inputFrame, Imgproc.COLOR_RGBA2RGB);
fMaskMOG = new Mat(inputFrame.size(),inputFrame.channels());
pMOG.apply(inputFrame, fMaskMOG);
//Mat frame = inputFrame.submat(Calibracion.getInstance().getRectPOI());
//fMaskMOG = new Mat(frame.size(),frame.channels());
//pMOG.apply(frame, fMaskMOG);
//Imgproc.resize(inputFrame, frame, frame.size());
//Log.i(TAG, "Size frame= " + frame.size());
//Log.i(TAG, "Size fMaskMOG= " + fMaskMOG.size());
//Rect aux = Calibracion.getInstance().getRectPOI();
//frame.copyTo(frame,fMaskMOG);
//Mat subMat = inputFrame.submat(0,frame.rows(),0,frame.cols());
//frame.copyTo(subMat);
//Mat frame = new Mat();
//inputFrame.copyTo(frame,fMaskMOG);
return fMaskMOG;
}
}
import java.io.*;
import java.net.*;
class TCPClient {
public static void main(String argv[]) throws Exception
{
String sentence;
String modifiedSentence;
BufferedReader inFromUser =
new BufferedReader(new InputStreamReader(System.in));
Socket clientSocket = new Socket("192.168.1.21", 5555);
DataOutputStream outToServer =
new DataOutputStream(clientSocket.getOutputStream());
BufferedReader inFromServer =
new BufferedReader(new
InputStreamReader(clientSocket.getInputStream()));
sentence = inFromUser.readLine();
outToServer.writeBytes(sentence + '\n');
modifiedSentence = inFromServer.readLine();
System.out.println("FROM SERVER: " + modifiedSentence);
clientSocket.close();
}
}