SlideShare a Scribd company logo
package VStabillization;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.Buffer;
import java.util.ArrayList;
import java.util.List;
import java.util.TimerTask;
public class PlayImage {
private int width = 480;
private int height = 270;
private int current = 0;
private int loadFrame = 100;
private int loadedFrame = -1;
private Object currentLock = new Object();
private final int intervalTime = 66;// 66;
private TimerTask updateFrameTimerTask;
private Thread imgs;
private Integer[] locks;
private BufferedImage[] bufferedImgs;
private int last = -1;
private String filename;
private int motionlessFrame = 0;
private double[] evaluateMotionResult;
private double[] evaluateSimilarityResult;
private double[] evaluateSimilarityByColorResult;
public FrameTransformation[] frameTransformationResult;
public FrameTransformation[] newTransformResult;
private int diffByColorThreshold = 100000;
private boolean processFinished = false;
private int[] frameNumberToPlay;
private double[] evaluateSenceChangeResult;
private int windowWidth = 30;
private BufferedImage[] adjustedImages;
private int debugProcessRatio = 1;
// peter
public int[][][] histogram = new int[4][4][4];
public int[][][] nextHistogram = new int[4][4][4];
public int frameRate = 15;
public int secForScene = 5;
public int SceneFrameCounter = 0;
public boolean findNextScene = false;
public int senceDiff = 0;
public int senceThreshold = 5000000;
public int[] sumFrame;
public int numOfFrame = 0;
public int sumIndex = 0;
public int[] senceChangeFrame;
public int senceChangeIndex = 0;
private boolean finished = false;
private BufferedImage compareImage;
// peter
public PlayImage(final String filename) {
this.filename = filename;
File file = new File(filename);
// long len = file.length();
long len = width * height * 3;
bufferedImgs = new BufferedImage[(int) (file.length() / len)];
// peter
sumFrame = new int[(int) (file.length() / len)];
senceChangeFrame = new int[(int) (file.length() / len)];
senceChangeFrame[0] = 0;
// peter
locks = new Integer[bufferedImgs.length];
for (int i = 0; i != locks.length; i++) {
locks[i] = new Integer(i);
}
Thread read = new Thread() {
public void run() {
PlayImage.this.allFrames(filename);
PlayImage.this.frameTransformationResult =
PlayImage.this.getEvaluateFrameTransformationResult();
PlayImage.this.newTransformResult =
PlayImage.this.getNewTransformResult(0,
frameTransformationResult.length/debugProcessRatio);
PlayImage.this.adjustedImages
=PlayImage.this.adjustFrames();
// PlayImage.this.evaluateSimilarityResult =
PlayImage.this.getEvaluateSimilarityResult();
// for (int i = 0; i !=
PlayImage.this.evaluateSimilarityResult.length; i++) {
// System.out.printf("%d: %fn", i,
PlayImage.this.evaluateSimilarityResult[i]);
// }
// int maxOrder =
PlayImage.this.findMaxOrder(PlayImage.this.evaluateSimilarityResult);
// PlayImage.this.evaluateSimilarityByColorResult =
PlayImage.this.getEvaluateSimilarityByColorResult(maxOrder);
//
// PlayImage.this.frameNumberToPlay =
PlayImage.this.generateFrameNumberToPlay();
// System.out.println("frameNumberToPlay");
// System.out.println(PlayImage.this.frameNumberToPlay[0]);
//// for (int i = 0; i !=
PlayImage.this.frameNumberToPlay.length; i++) {
////
System.out.println(PlayImage.this.frameNumberToPlay[i]);
//// }
frameNumberToPlay = new int[bufferedImgs.length-1];
for(int i = 0; i != frameNumberToPlay.length-1; i++){
frameNumberToPlay[i] = i;
}
CommunicateVariables communicateVariables =
CommunicateVariables.getSingular();
communicateVariables.imageIndexInput(frameNumberToPlay);
while(! communicateVariables.finished()){
try {
Thread.sleep(10);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//
// frameNumberToPlay = communicateVariables.getIndex();
//// for (int i = 0; i !=
PlayImage.this.frameNumberToPlay.length; i++) {
////
System.out.println(PlayImage.this.frameNumberToPlay[i]);
//// }
processFinished = true;
System.out.println(processFinished);
}
};
read.start();
}
public BufferedImage[] adjustFrames(){
EvaluateFrameTransformation evaluateFrameTransformation = new
EvaluateFrameTransformationByOpenCV();
BufferedImage[] result = new BufferedImage[bufferedImgs.length];
for(int i = 0 ; i!= bufferedImgs.length/debugProcessRatio; i++){
result[i] = adjustFrame(bufferedImgs[i],
newTransformResult[i]);
//result[i] =
evaluateFrameTransformation.applyTransformToImage(bufferedImgs[i],
newPrevToCurResult[i]);
}
return result;
}
public BufferedImage adjustFrame(BufferedImage img, FrameTransformation
frameTransformation){
BufferedImage img2 = new BufferedImage(img.getWidth(),
img.getHeight(), img.getType());
for(int i = 0; i != img.getWidth(); i++){
for(int j = 0; j != img.getHeight(); j++){
int tempX = (int) (i + frameTransformation.getDy());
int tempY = (int) (j + frameTransformation.getDx());
if( tempX >= 0 && tempX< img.getWidth() && tempY >= 0 &&
tempY < img.getHeight()){
img2.setRGB(tempX, tempY, img.getRGB(i, j));
}
}
}
return img2;
}
public double findMax(double[] value){
double max = value[0];
for(int i = 0; i!= value.length; i++){
if(max < value[i]){
max = value[i];
}
}
return max;
}
public int findMaxOrder(double[] value){
double max = value[0];
int order = 0;
for(int i = 0; i!= value.length; i++){
if(max < value[i]){
max = value[i];
order = i;
}
}
return order;
}
public int getCurrent(){
synchronized (currentLock) {
return this.current;
}
}
public double[] getSenceChangeResult(){
double[] result = new double[bufferedImgs.length];
List<Integer> temp = new ArrayList<>();
temp.add(0);
for(int i = 0; i != senceChangeFrame.length; i++){
if(senceChangeFrame[i] != 0){
temp.add(senceChangeFrame[i]);
System.out.println(senceChangeFrame[i]);
}
}
for(int i = 0; i != temp.size(); i++){
for(int j = 0 ; j != frameRate * secForScene; j++){
if(i+j < result.length){
result[temp.get(i)+j] = 500;
}
}
}
return result;
}
public int[] generateFrameNumberToPlay(double valve) {
double[] evaluateValue = getEvaluateValue();
int[] temp = new int[bufferedImgs.length];
int current = 0;
for (int i = 0; i != evaluateValue.length; i++) {
if (evaluateValue[i] > valve) {
temp[current] = i;
current++;
}
}
System.out.println(current);
return temp;
}
public int[] generateFrameNumberToPlay() {
double[] evaluateValue = getEvaluateValue();
int[] temp = new int[bufferedImgs.length];
int current = 0;
double max = -1000;
int order = 0;
for (int i = 0; i != evaluateValue.length; i++) {
if (evaluateValue[i] > max) {
max = evaluateValue[i];
order = i;
}
}
int start = order;
while(start > 1){
if(evaluateSimilarityByColorResult[start] >
diffByColorThreshold){
break;
}
else{
start-=1;
}
}
int end = order+1;
while(end < evaluateValue.length){
if(evaluateSimilarityByColorResult[end-1] >
diffByColorThreshold){
break;
}
else{
end+=1;
}
}
for(int i = 0; i != end-start; i++){
temp[i] = i+start;
}
// System.out.println(current);
System.out.printf("Start: %d", start);
System.out.printf("End: %d", end);
return temp;
}
public double[] getEvaluateValue() {
double[] result = new double[bufferedImgs.length];
for(int i = 0; i != result.length; i++){
result[i] = evaluateSimilarityResult[i];
}
return result;
}
public BufferedImage getCurrentImageProcessed() {
if (this.processFinished == false) {
return null;
}
synchronized (currentLock) {
if (current >= bufferedImgs.length) {
this.finished = true;
return null;
}
synchronized (locks[current]) {
if (last == current) {
return null;
} else {
last = current;
// return bufferedImgs[current];
return adjustedImages[current];
}
}
}
}
public double[] getEvaluateSimilarityByColorResult(int order){
EvaluateSimilarity evaluateSimilarity = new
EvaluateSimilarityByColor();
double[] result = new double[bufferedImgs.length];
result[0] = 0;
System.out.println("Color");
for (int i = 0; i < bufferedImgs.length; i++) {
result[i] = evaluateSimilarity.evaluateSimilarityBetweenImage(
bufferedImgs[i], bufferedImgs[order]);
System.out.printf("%d: %fn", i, result[i]);
}
return result;
}
public double[] getEvaluateSimilarityResult(){
EvaluateSimilarity evaluateSimilarity = new
EvaluateSimilarityByRescale();
double[] result = new double[bufferedImgs.length];
result[0] = 0;
for (int i = 0; i < bufferedImgs.length; i++) {
result[i] = evaluateSimilarity.evaluateSimilarityBetweenImage(
bufferedImgs[i], compareImage);
}
return result;
}
public FrameTransformation[] getEvaluateFrameTransformationResult(){
EvaluateFrameTransformation evaluateFrameTransformation = new
EvaluateFrameTransformationByOpenCV();
FrameTransformation[] result = new
FrameTransformation[bufferedImgs.length];
result[0] = new FrameTransformation(0, 0, 0);
for (int i = 1; i < bufferedImgs.length/debugProcessRatio; i++) {
BufferedImage temp, temp2;
synchronized (locks[i-1]) {
temp = bufferedImgs[i-1];
}
synchronized (locks[i]) {
temp2 = bufferedImgs[i];
}
result[i] =
evaluateFrameTransformation.evaluateMotionBetweenImage(
temp, temp2);
}
return result;
}
public FrameTransformation[] getNewTransformResult(int start, int end){
double a = 0;
double x = 0;
double y = 0;
List<FrameTransformation> path = new ArrayList<>();
for(int i = start; i< end; i++){
x += frameTransformationResult[i].getDx();
y += frameTransformationResult[i].getDy();
a += frameTransformationResult[i].getDa();
path.add(new FrameTransformation(x, y, a));
}
List<FrameTransformation> pathWithWindow = new ArrayList<>();
for(int i = 0; i < end-start; i++){
double xTotal = 0;
double yTotal = 0;
double aTotal = 0;
int number = 0;
for(int j=-windowWidth; j <= windowWidth; j++){
if(i+j>=0 && i+j < end-start){
xTotal += path.get(i+j).getDx();
yTotal += path.get(i+j).getDy();
aTotal += path.get(i+j).getDa();
number++;
}
}
double aAvg = aTotal /number;
double xAvg = xTotal/number;
double yAvg = yTotal / number;
pathWithWindow.add(new FrameTransformation(xAvg,yAvg, aAvg));
}
List<FrameTransformation> newFrameTransformation = new
ArrayList<>();
a = 0;
x = 0;
y = 0;
for(int i = 0; i < end-start; i++){
x+= frameTransformationResult[i+start].getDx();
y+= frameTransformationResult[i+start].getDy();
a+= frameTransformationResult[i+start].getDa();
double xDist = pathWithWindow.get(i).getDx() - x;
double yDist = pathWithWindow.get(i).getDy() - y;
double aDist = pathWithWindow.get(i).getDa() - a;
double dx = frameTransformationResult[i+start].getDx() +
xDist;
double dy = frameTransformationResult[i+start].getDy() +
yDist;
double da = frameTransformationResult[i+start].getDa() +
aDist;
newFrameTransformation.add(new FrameTransformation(dx, dy,
da));
}
FrameTransformation[] result = new
FrameTransformation[newFrameTransformation.size()];
for(int i = 0 ;i != result.length; i++){
result[i] = newFrameTransformation.get(i);
}
return result;
}
public double[] getEvaluateMotionResult() {
// EvaluateMotion evaluateMotion = new
EvaluateMotionByFramePredict(15,
// 15, 5, 5);
EvaluateMotion evaluateMotion = new
EvaluateMotionByCompareAverageValueInBlock(
15, 15, 500);
double[] result = new double[bufferedImgs.length];
result[0] = 0;
for (int i = 1; i < bufferedImgs.length; i++) {
BufferedImage temp, temp2;
synchronized (locks[i-1]) {
temp = bufferedImgs[i-1];
}
synchronized (locks[i]) {
temp2 = bufferedImgs[i];
}
result[i] = evaluateMotion.evaluateMotionBetweenImage(
temp, temp2);
}
double temp = 0;
for (int i = 0; i < bufferedImgs.length; i+= frameRate) {
for(int j = 0; j != frameRate; j++){
if(temp < result[i+j]){
temp= result[i+j];
}
}
for(int j = 0; j != frameRate; j++){
result[i+j] = temp;
}
}
return result;
}
// public BufferedImage readRightImg(){
//
// }
public BufferedImage getFirstImage() {
BufferedImage img = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
InputStream is = null;
File file = new File(this.filename);
try {
is = new FileInputStream(file);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// long len = file.length();
long len = width * height * 3;
bufferedImgs = new BufferedImage[(int) (file.length() / len)];
byte[] bytes = new byte[(int) len];
int offset = 0;
int numRead = 0;
try {
while (offset < bytes.length
&& (numRead = is.read(bytes, offset, bytes.length
- offset)) >= 0) {
offset += numRead;
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int ind = 0;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
byte a = 0;
byte r = bytes[ind];
byte g = bytes[ind + height * width];
byte b = bytes[ind + height * width * 2];
int pix = 0xff000000 | ((r & 0xff) << 16) | ((g & 0xff)
<< 8)
| (b & 0xff);
// int pix = ((a << 24) + (r << 16) + (g << 8) + b);
img.setRGB(x, y, pix);
ind++;
}
}
try {
is.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return img;
}
public void allFrames(String filename) {
try {
File file = new File(filename);
InputStream is = new FileInputStream(file);
allFrames(is);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public boolean isFinished(){
return finished;
}
public void allFrames(InputStream is) {
try {
for (int i = 0; i < bufferedImgs.length; i++) {
synchronized (locks[i]) {
if (bufferedImgs[i] == null) {
BufferedImage temp = readNextFrame(is);
bufferedImgs[i] = temp;
loadedFrame = i;
}
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
}
}
public BufferedImage readNextFrame(InputStream is) throws IOException {
BufferedImage img = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
// long len = file.length();
long len = width * height * 3;
byte[] bytes = new byte[(int) len];
int offset = 0;
int numRead = 0;
while (offset < bytes.length
&& (numRead = is.read(bytes, offset, bytes.length -
offset)) >= 0) {
offset += numRead;
}
int ind = 0;
if (findNextScene) {
SceneFrameCounter = 0;
// System.out.println("findNextScene" + findNextScene);
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
byte a = 0;
byte r = bytes[ind];
byte g = bytes[ind + height * width];
byte b = bytes[ind + height * width * 2];
// peter
int red = r;
if (r < 0)
red = red + 256;
int green = g;
if (g < 0)
green = green + 256;
int blue = b;
if (b < 0)
blue = blue + 256;
r = (byte) red;
g = (byte) green;
b = (byte) blue;
nextHistogram[red / 64][green / 64][blue / 64]++;
int pix = 0xff000000 | ((r & 0xff) << 16)
| ((g & 0xff) << 8) | (b & 0xff);
// int pix = ((a << 24) + (r << 16) + (g << 8) +
b);
img.setRGB(x, y, pix);
ind++;
}
}
for (int i = 0; i < histogram.length; i++)
for (int j = 0; j < histogram[i].length; j++)
for (int p = 0; p < histogram[i][j].length; p++) {
senceDiff = Math.abs(histogram[i][j][p]
- nextHistogram[i][j][p]);
}
if (senceDiff >= senceThreshold) {
findNextScene = false;
for (int i = 0; i < histogram.length; i++)
for (int j = 0; j < histogram[i].length; j++)
for (int p = 0; p < histogram[i][j].length;
p++) {
histogram[i][j][p] = nextHistogram[i]
[j][p];
}
senceChangeIndex++;
senceChangeFrame[senceChangeIndex] = numOfFrame;
}
senceDiff = 0;
} else {
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
byte a = 0;
byte r = bytes[ind];
byte g = bytes[ind + height * width];
byte b = bytes[ind + height * width * 2];
// peter
if (SceneFrameCounter >= frameRate * secForScene)
{
int red = r;
if (r < 0)
red = red + 256;
int green = g;
if (g < 0)
green = green + 256;
int blue = b;
if (b < 0)
blue = blue + 256;
r = (byte) red;
g = (byte) green;
b = (byte) blue;
histogram[red / 64][green / 64][blue / 64]+
+;
findNextScene = true;
}
// peter
// for(int i = 0; i < histogram.length; i++)
// for(int j = 0; j < histogram[i].length; j++)
// for(int p = 0; p < histogram[i][j].length; p++)
{
//
// }
int pix = 0xff000000 | ((r & 0xff) << 16)
| ((g & 0xff) << 8) | (b & 0xff);
// int pix = ((a << 24) + (r << 16) + (g << 8) +
b);
img.setRGB(x, y, pix);
ind++;
}
}
sumFrame[sumIndex] = numOfFrame;
sumIndex++;
SceneFrameCounter++;
// System.out.println(SceneFrameCounter);
}
numOfFrame++;
return img;
}
public BufferedImage getImg(int order) {
if (order >= bufferedImgs.length) {
return null;
}
synchronized (locks[order]) {
return bufferedImgs[order];
}
}
public BufferedImage getCurrentImg() {
if (this.processFinished == false) {
return null;
}
synchronized (currentLock) {
if (current >= bufferedImgs.length) {
this.finished = true;
return null;
}
synchronized (locks[current]) {
if (last == current) {
return null;
} else {
last = current;
return bufferedImgs[current];
// return adjustedImages[current];
}
}
}
}
public BufferedImage getCurrentImgScenery() {
synchronized (currentLock) {
if (current >= bufferedImgs.length) {
return null;
}
synchronized (locks[current]) {
if (last == current) {
return null;
} else {
last = current;
return bufferedImgs[sumFrame[current]];
}
}
}
}
public void start() {
PlayImage.this.current = 0;
if (updateFrameTimerTask != null) {
updateFrameTimerTask.cancel();
}
java.util.Timer updateFrameTimer = new java.util.Timer();
updateFrameTimerTask = new TimerTask() {
public void run() {
synchronized (PlayImage.this.currentLock) {
// System.out.printf("%d:
PlayImagen",PlayImage.this.current);
PlayImage.this.current++;
}
}
};
System.out.println("start");
updateFrameTimer.scheduleAtFixedRate(updateFrameTimerTask, 0,
PlayImage.this.intervalTime);
}
public void pause() {
if (updateFrameTimerTask != null) {
updateFrameTimerTask.cancel();
}
}
public void startOrContinue() {
if (updateFrameTimerTask == null) {
this.start();
} else {
this.avContinue();
}
}
public void avContinue() {
java.util.Timer updateFrameTimer = new java.util.Timer();
updateFrameTimerTask = new TimerTask() {
public void run() {
synchronized (PlayImage.this.currentLock) {
PlayImage.this.current++;
}
}
};
updateFrameTimer.scheduleAtFixedRate(updateFrameTimerTask, 0,
PlayImage.this.intervalTime);
}
}

More Related Content

What's hot

Threads, Queues, and More: Async Programming in iOS
Threads, Queues, and More: Async Programming in iOSThreads, Queues, and More: Async Programming in iOS
Threads, Queues, and More: Async Programming in iOS
TechWell
 
14 thread
14 thread14 thread
14 thread
Bayarkhuu
 
Java Concurrency
Java ConcurrencyJava Concurrency
Java Concurrency
Carol McDonald
 
Elixir and OTP Apps introduction
Elixir and OTP Apps introductionElixir and OTP Apps introduction
Elixir and OTP Apps introduction
Gonzalo Gabriel Jiménez Fuentes
 
The Ring programming language version 1.8 book - Part 31 of 202
The Ring programming language version 1.8 book - Part 31 of 202The Ring programming language version 1.8 book - Part 31 of 202
The Ring programming language version 1.8 book - Part 31 of 202
Mahmoud Samir Fayed
 
分散式系統
分散式系統分散式系統
分散式系統
acksinkwung
 
C# Advanced L04-Threading
C# Advanced L04-ThreadingC# Advanced L04-Threading
C# Advanced L04-Threading
Mohammad Shaker
 
concurrency_c#_public
concurrency_c#_publicconcurrency_c#_public
concurrency_c#_public
Paul Churchward
 
Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.
Kuldeep Jain
 
Threads in python
Threads in pythonThreads in python
The Ring programming language version 1.8 book - Part 87 of 202
The Ring programming language version 1.8 book - Part 87 of 202The Ring programming language version 1.8 book - Part 87 of 202
The Ring programming language version 1.8 book - Part 87 of 202
Mahmoud Samir Fayed
 
Making Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVMMaking Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVM
Rafael Winterhalter
 
Sam wd programs
Sam wd programsSam wd programs
Sam wd programs
Soumya Behera
 
Poly-paradigm Java
Poly-paradigm JavaPoly-paradigm Java
Poly-paradigm Java
Pavel Tcholakov
 
Java.lang.object
Java.lang.objectJava.lang.object
Java.lang.object
Soham Sengupta
 
Python multithreading
Python multithreadingPython multithreading
The Ring programming language version 1.5.1 book - Part 9 of 180
The Ring programming language version 1.5.1 book - Part 9 of 180The Ring programming language version 1.5.1 book - Part 9 of 180
The Ring programming language version 1.5.1 book - Part 9 of 180
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 94 of 212
The Ring programming language version 1.10 book - Part 94 of 212The Ring programming language version 1.10 book - Part 94 of 212
The Ring programming language version 1.10 book - Part 94 of 212
Mahmoud Samir Fayed
 
Java Concurrency by Example
Java Concurrency by ExampleJava Concurrency by Example
Java Concurrency by Example
Ganesh Samarthyam
 
Add an interactive command line to your C++ application
Add an interactive command line to your C++ applicationAdd an interactive command line to your C++ application
Add an interactive command line to your C++ application
Daniele Pallastrelli
 

What's hot (20)

Threads, Queues, and More: Async Programming in iOS
Threads, Queues, and More: Async Programming in iOSThreads, Queues, and More: Async Programming in iOS
Threads, Queues, and More: Async Programming in iOS
 
14 thread
14 thread14 thread
14 thread
 
Java Concurrency
Java ConcurrencyJava Concurrency
Java Concurrency
 
Elixir and OTP Apps introduction
Elixir and OTP Apps introductionElixir and OTP Apps introduction
Elixir and OTP Apps introduction
 
The Ring programming language version 1.8 book - Part 31 of 202
The Ring programming language version 1.8 book - Part 31 of 202The Ring programming language version 1.8 book - Part 31 of 202
The Ring programming language version 1.8 book - Part 31 of 202
 
分散式系統
分散式系統分散式系統
分散式系統
 
C# Advanced L04-Threading
C# Advanced L04-ThreadingC# Advanced L04-Threading
C# Advanced L04-Threading
 
concurrency_c#_public
concurrency_c#_publicconcurrency_c#_public
concurrency_c#_public
 
Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.
 
Threads in python
Threads in pythonThreads in python
Threads in python
 
The Ring programming language version 1.8 book - Part 87 of 202
The Ring programming language version 1.8 book - Part 87 of 202The Ring programming language version 1.8 book - Part 87 of 202
The Ring programming language version 1.8 book - Part 87 of 202
 
Making Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVMMaking Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVM
 
Sam wd programs
Sam wd programsSam wd programs
Sam wd programs
 
Poly-paradigm Java
Poly-paradigm JavaPoly-paradigm Java
Poly-paradigm Java
 
Java.lang.object
Java.lang.objectJava.lang.object
Java.lang.object
 
Python multithreading
Python multithreadingPython multithreading
Python multithreading
 
The Ring programming language version 1.5.1 book - Part 9 of 180
The Ring programming language version 1.5.1 book - Part 9 of 180The Ring programming language version 1.5.1 book - Part 9 of 180
The Ring programming language version 1.5.1 book - Part 9 of 180
 
The Ring programming language version 1.10 book - Part 94 of 212
The Ring programming language version 1.10 book - Part 94 of 212The Ring programming language version 1.10 book - Part 94 of 212
The Ring programming language version 1.10 book - Part 94 of 212
 
Java Concurrency by Example
Java Concurrency by ExampleJava Concurrency by Example
Java Concurrency by Example
 
Add an interactive command line to your C++ application
Add an interactive command line to your C++ applicationAdd an interactive command line to your C++ application
Add an interactive command line to your C++ application
 

Similar to Play image

Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Sunil Kumar Gunasekaran
 
Android Threading
Android ThreadingAndroid Threading
Android Threading
Jussi Pohjolainen
 
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
DroidConTLV
 
import java-util-Arrays- import java-io-PrintWriter- import java-io-Fi.pdf
import java-util-Arrays- import java-io-PrintWriter- import java-io-Fi.pdfimport java-util-Arrays- import java-io-PrintWriter- import java-io-Fi.pdf
import java-util-Arrays- import java-io-PrintWriter- import java-io-Fi.pdf
adhityalapcare
 
Hi, I need some one to help me with Design a client-server Chat so.pdf
Hi, I need some one to help me with Design a client-server Chat so.pdfHi, I need some one to help me with Design a client-server Chat so.pdf
Hi, I need some one to help me with Design a client-server Chat so.pdf
fashiongallery1
 
Thread
ThreadThread
Thread
phanleson
 
Solit 2013, Автоматизация тестирования сложных систем: mixed mode automated t...
Solit 2013, Автоматизация тестирования сложных систем: mixed mode automated t...Solit 2013, Автоматизация тестирования сложных систем: mixed mode automated t...
Solit 2013, Автоматизация тестирования сложных систем: mixed mode automated t...
solit
 
please help finish sorting methods- import java-util-Arrays- import ja.pdf
please help finish sorting methods- import java-util-Arrays- import ja.pdfplease help finish sorting methods- import java-util-Arrays- import ja.pdf
please help finish sorting methods- import java-util-Arrays- import ja.pdf
anfenterprises
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Domenic Denicola
 
C#을 이용한 task 병렬화와 비동기 패턴
C#을 이용한 task 병렬화와 비동기 패턴C#을 이용한 task 병렬화와 비동기 패턴
C#을 이용한 task 병렬화와 비동기 패턴
명신 김
 
Please help!!I wanted to know how to add a high score to this prog.pdf
Please help!!I wanted to know how to add a high score to this prog.pdfPlease help!!I wanted to know how to add a high score to this prog.pdf
Please help!!I wanted to know how to add a high score to this prog.pdf
JUSTSTYLISH3B2MOHALI
 
Orsiso
OrsisoOrsiso
Orsiso
e27
 
Learning Java 1 – Introduction
Learning Java 1 – IntroductionLearning Java 1 – Introduction
Learning Java 1 – Introduction
caswenson
 
JavaExamples
JavaExamplesJavaExamples
JavaExamples
Suman Astani
 
HTML5って必要?
HTML5って必要?HTML5って必要?
HTML5って必要?
GCS2013
 
Java practical
Java practicalJava practical
Java practical
shweta-sharma99
 
C346_PA3_W12srccommonBaseThread.javaC346_PA3_W12srccommonB.docx
C346_PA3_W12srccommonBaseThread.javaC346_PA3_W12srccommonB.docxC346_PA3_W12srccommonBaseThread.javaC346_PA3_W12srccommonB.docx
C346_PA3_W12srccommonBaseThread.javaC346_PA3_W12srccommonB.docx
humphrieskalyn
 
Griffon @ Svwjug
Griffon @ SvwjugGriffon @ Svwjug
Griffon @ Svwjug
Andres Almiray
 
Java tut1
Java tut1Java tut1
Java tut1
Ajmal Khan
 
Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
Vijay A Raj
 

Similar to Play image (20)

Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
 
Android Threading
Android ThreadingAndroid Threading
Android Threading
 
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
 
import java-util-Arrays- import java-io-PrintWriter- import java-io-Fi.pdf
import java-util-Arrays- import java-io-PrintWriter- import java-io-Fi.pdfimport java-util-Arrays- import java-io-PrintWriter- import java-io-Fi.pdf
import java-util-Arrays- import java-io-PrintWriter- import java-io-Fi.pdf
 
Hi, I need some one to help me with Design a client-server Chat so.pdf
Hi, I need some one to help me with Design a client-server Chat so.pdfHi, I need some one to help me with Design a client-server Chat so.pdf
Hi, I need some one to help me with Design a client-server Chat so.pdf
 
Thread
ThreadThread
Thread
 
Solit 2013, Автоматизация тестирования сложных систем: mixed mode automated t...
Solit 2013, Автоматизация тестирования сложных систем: mixed mode automated t...Solit 2013, Автоматизация тестирования сложных систем: mixed mode automated t...
Solit 2013, Автоматизация тестирования сложных систем: mixed mode automated t...
 
please help finish sorting methods- import java-util-Arrays- import ja.pdf
please help finish sorting methods- import java-util-Arrays- import ja.pdfplease help finish sorting methods- import java-util-Arrays- import ja.pdf
please help finish sorting methods- import java-util-Arrays- import ja.pdf
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
 
C#을 이용한 task 병렬화와 비동기 패턴
C#을 이용한 task 병렬화와 비동기 패턴C#을 이용한 task 병렬화와 비동기 패턴
C#을 이용한 task 병렬화와 비동기 패턴
 
Please help!!I wanted to know how to add a high score to this prog.pdf
Please help!!I wanted to know how to add a high score to this prog.pdfPlease help!!I wanted to know how to add a high score to this prog.pdf
Please help!!I wanted to know how to add a high score to this prog.pdf
 
Orsiso
OrsisoOrsiso
Orsiso
 
Learning Java 1 – Introduction
Learning Java 1 – IntroductionLearning Java 1 – Introduction
Learning Java 1 – Introduction
 
JavaExamples
JavaExamplesJavaExamples
JavaExamples
 
HTML5って必要?
HTML5って必要?HTML5って必要?
HTML5って必要?
 
Java practical
Java practicalJava practical
Java practical
 
C346_PA3_W12srccommonBaseThread.javaC346_PA3_W12srccommonB.docx
C346_PA3_W12srccommonBaseThread.javaC346_PA3_W12srccommonB.docxC346_PA3_W12srccommonBaseThread.javaC346_PA3_W12srccommonB.docx
C346_PA3_W12srccommonBaseThread.javaC346_PA3_W12srccommonB.docx
 
Griffon @ Svwjug
Griffon @ SvwjugGriffon @ Svwjug
Griffon @ Svwjug
 
Java tut1
Java tut1Java tut1
Java tut1
 
Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
 

Recently uploaded

Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
PsychoTech Services
 
B. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdfB. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdf
BoudhayanBhattachari
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47
MysoreMuleSoftMeetup
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
S. Raj Kumar
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdfIGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
Amin Marwan
 
ZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptxZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptx
dot55audits
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
math operations ued in python and all used
math operations ued in python and all usedmath operations ued in python and all used
math operations ued in python and all used
ssuser13ffe4
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
haiqairshad
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
MJDuyan
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 

Recently uploaded (20)

Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
 
B. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdfB. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdf
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdfIGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
 
ZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptxZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptx
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
math operations ued in python and all used
math operations ued in python and all usedmath operations ued in python and all used
math operations ued in python and all used
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 

Play image

  • 1. package VStabillization; import java.awt.image.BufferedImage; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.nio.Buffer; import java.util.ArrayList; import java.util.List; import java.util.TimerTask; public class PlayImage { private int width = 480; private int height = 270; private int current = 0; private int loadFrame = 100; private int loadedFrame = -1; private Object currentLock = new Object(); private final int intervalTime = 66;// 66; private TimerTask updateFrameTimerTask; private Thread imgs; private Integer[] locks; private BufferedImage[] bufferedImgs; private int last = -1; private String filename; private int motionlessFrame = 0; private double[] evaluateMotionResult; private double[] evaluateSimilarityResult; private double[] evaluateSimilarityByColorResult; public FrameTransformation[] frameTransformationResult; public FrameTransformation[] newTransformResult; private int diffByColorThreshold = 100000; private boolean processFinished = false; private int[] frameNumberToPlay; private double[] evaluateSenceChangeResult; private int windowWidth = 30; private BufferedImage[] adjustedImages; private int debugProcessRatio = 1; // peter public int[][][] histogram = new int[4][4][4]; public int[][][] nextHistogram = new int[4][4][4]; public int frameRate = 15; public int secForScene = 5; public int SceneFrameCounter = 0; public boolean findNextScene = false; public int senceDiff = 0; public int senceThreshold = 5000000; public int[] sumFrame; public int numOfFrame = 0; public int sumIndex = 0; public int[] senceChangeFrame; public int senceChangeIndex = 0; private boolean finished = false; private BufferedImage compareImage; // peter public PlayImage(final String filename) {
  • 2. this.filename = filename; File file = new File(filename); // long len = file.length(); long len = width * height * 3; bufferedImgs = new BufferedImage[(int) (file.length() / len)]; // peter sumFrame = new int[(int) (file.length() / len)]; senceChangeFrame = new int[(int) (file.length() / len)]; senceChangeFrame[0] = 0; // peter locks = new Integer[bufferedImgs.length]; for (int i = 0; i != locks.length; i++) { locks[i] = new Integer(i); } Thread read = new Thread() { public void run() { PlayImage.this.allFrames(filename); PlayImage.this.frameTransformationResult = PlayImage.this.getEvaluateFrameTransformationResult(); PlayImage.this.newTransformResult = PlayImage.this.getNewTransformResult(0, frameTransformationResult.length/debugProcessRatio); PlayImage.this.adjustedImages =PlayImage.this.adjustFrames(); // PlayImage.this.evaluateSimilarityResult = PlayImage.this.getEvaluateSimilarityResult(); // for (int i = 0; i != PlayImage.this.evaluateSimilarityResult.length; i++) { // System.out.printf("%d: %fn", i, PlayImage.this.evaluateSimilarityResult[i]); // } // int maxOrder = PlayImage.this.findMaxOrder(PlayImage.this.evaluateSimilarityResult); // PlayImage.this.evaluateSimilarityByColorResult = PlayImage.this.getEvaluateSimilarityByColorResult(maxOrder); // // PlayImage.this.frameNumberToPlay = PlayImage.this.generateFrameNumberToPlay(); // System.out.println("frameNumberToPlay"); // System.out.println(PlayImage.this.frameNumberToPlay[0]); //// for (int i = 0; i != PlayImage.this.frameNumberToPlay.length; i++) { //// System.out.println(PlayImage.this.frameNumberToPlay[i]); //// } frameNumberToPlay = new int[bufferedImgs.length-1]; for(int i = 0; i != frameNumberToPlay.length-1; i++){ frameNumberToPlay[i] = i; } CommunicateVariables communicateVariables = CommunicateVariables.getSingular(); communicateVariables.imageIndexInput(frameNumberToPlay); while(! communicateVariables.finished()){ try { Thread.sleep(10); } catch (InterruptedException e) { // TODO Auto-generated catch block
  • 3. e.printStackTrace(); } } // // frameNumberToPlay = communicateVariables.getIndex(); //// for (int i = 0; i != PlayImage.this.frameNumberToPlay.length; i++) { //// System.out.println(PlayImage.this.frameNumberToPlay[i]); //// } processFinished = true; System.out.println(processFinished); } }; read.start(); } public BufferedImage[] adjustFrames(){ EvaluateFrameTransformation evaluateFrameTransformation = new EvaluateFrameTransformationByOpenCV(); BufferedImage[] result = new BufferedImage[bufferedImgs.length]; for(int i = 0 ; i!= bufferedImgs.length/debugProcessRatio; i++){ result[i] = adjustFrame(bufferedImgs[i], newTransformResult[i]); //result[i] = evaluateFrameTransformation.applyTransformToImage(bufferedImgs[i], newPrevToCurResult[i]); } return result; } public BufferedImage adjustFrame(BufferedImage img, FrameTransformation frameTransformation){ BufferedImage img2 = new BufferedImage(img.getWidth(), img.getHeight(), img.getType()); for(int i = 0; i != img.getWidth(); i++){ for(int j = 0; j != img.getHeight(); j++){ int tempX = (int) (i + frameTransformation.getDy()); int tempY = (int) (j + frameTransformation.getDx()); if( tempX >= 0 && tempX< img.getWidth() && tempY >= 0 && tempY < img.getHeight()){ img2.setRGB(tempX, tempY, img.getRGB(i, j)); } } } return img2; } public double findMax(double[] value){ double max = value[0]; for(int i = 0; i!= value.length; i++){ if(max < value[i]){ max = value[i]; } } return max; } public int findMaxOrder(double[] value){ double max = value[0]; int order = 0; for(int i = 0; i!= value.length; i++){ if(max < value[i]){ max = value[i]; order = i;
  • 4. } } return order; } public int getCurrent(){ synchronized (currentLock) { return this.current; } } public double[] getSenceChangeResult(){ double[] result = new double[bufferedImgs.length]; List<Integer> temp = new ArrayList<>(); temp.add(0); for(int i = 0; i != senceChangeFrame.length; i++){ if(senceChangeFrame[i] != 0){ temp.add(senceChangeFrame[i]); System.out.println(senceChangeFrame[i]); } } for(int i = 0; i != temp.size(); i++){ for(int j = 0 ; j != frameRate * secForScene; j++){ if(i+j < result.length){ result[temp.get(i)+j] = 500; } } } return result; } public int[] generateFrameNumberToPlay(double valve) { double[] evaluateValue = getEvaluateValue(); int[] temp = new int[bufferedImgs.length]; int current = 0; for (int i = 0; i != evaluateValue.length; i++) { if (evaluateValue[i] > valve) { temp[current] = i; current++; } } System.out.println(current); return temp; } public int[] generateFrameNumberToPlay() { double[] evaluateValue = getEvaluateValue(); int[] temp = new int[bufferedImgs.length]; int current = 0; double max = -1000; int order = 0; for (int i = 0; i != evaluateValue.length; i++) { if (evaluateValue[i] > max) { max = evaluateValue[i]; order = i; } } int start = order; while(start > 1){ if(evaluateSimilarityByColorResult[start] >
  • 5. diffByColorThreshold){ break; } else{ start-=1; } } int end = order+1; while(end < evaluateValue.length){ if(evaluateSimilarityByColorResult[end-1] > diffByColorThreshold){ break; } else{ end+=1; } } for(int i = 0; i != end-start; i++){ temp[i] = i+start; } // System.out.println(current); System.out.printf("Start: %d", start); System.out.printf("End: %d", end); return temp; } public double[] getEvaluateValue() { double[] result = new double[bufferedImgs.length]; for(int i = 0; i != result.length; i++){ result[i] = evaluateSimilarityResult[i]; } return result; } public BufferedImage getCurrentImageProcessed() { if (this.processFinished == false) { return null; } synchronized (currentLock) { if (current >= bufferedImgs.length) { this.finished = true; return null; } synchronized (locks[current]) { if (last == current) { return null; } else { last = current; // return bufferedImgs[current]; return adjustedImages[current]; } } } } public double[] getEvaluateSimilarityByColorResult(int order){ EvaluateSimilarity evaluateSimilarity = new EvaluateSimilarityByColor(); double[] result = new double[bufferedImgs.length]; result[0] = 0;
  • 6. System.out.println("Color"); for (int i = 0; i < bufferedImgs.length; i++) { result[i] = evaluateSimilarity.evaluateSimilarityBetweenImage( bufferedImgs[i], bufferedImgs[order]); System.out.printf("%d: %fn", i, result[i]); } return result; } public double[] getEvaluateSimilarityResult(){ EvaluateSimilarity evaluateSimilarity = new EvaluateSimilarityByRescale(); double[] result = new double[bufferedImgs.length]; result[0] = 0; for (int i = 0; i < bufferedImgs.length; i++) { result[i] = evaluateSimilarity.evaluateSimilarityBetweenImage( bufferedImgs[i], compareImage); } return result; } public FrameTransformation[] getEvaluateFrameTransformationResult(){ EvaluateFrameTransformation evaluateFrameTransformation = new EvaluateFrameTransformationByOpenCV(); FrameTransformation[] result = new FrameTransformation[bufferedImgs.length]; result[0] = new FrameTransformation(0, 0, 0); for (int i = 1; i < bufferedImgs.length/debugProcessRatio; i++) { BufferedImage temp, temp2; synchronized (locks[i-1]) { temp = bufferedImgs[i-1]; } synchronized (locks[i]) { temp2 = bufferedImgs[i]; } result[i] = evaluateFrameTransformation.evaluateMotionBetweenImage( temp, temp2); } return result; } public FrameTransformation[] getNewTransformResult(int start, int end){ double a = 0; double x = 0; double y = 0; List<FrameTransformation> path = new ArrayList<>(); for(int i = start; i< end; i++){ x += frameTransformationResult[i].getDx(); y += frameTransformationResult[i].getDy(); a += frameTransformationResult[i].getDa(); path.add(new FrameTransformation(x, y, a)); } List<FrameTransformation> pathWithWindow = new ArrayList<>(); for(int i = 0; i < end-start; i++){ double xTotal = 0; double yTotal = 0; double aTotal = 0; int number = 0;
  • 7. for(int j=-windowWidth; j <= windowWidth; j++){ if(i+j>=0 && i+j < end-start){ xTotal += path.get(i+j).getDx(); yTotal += path.get(i+j).getDy(); aTotal += path.get(i+j).getDa(); number++; } } double aAvg = aTotal /number; double xAvg = xTotal/number; double yAvg = yTotal / number; pathWithWindow.add(new FrameTransformation(xAvg,yAvg, aAvg)); } List<FrameTransformation> newFrameTransformation = new ArrayList<>(); a = 0; x = 0; y = 0; for(int i = 0; i < end-start; i++){ x+= frameTransformationResult[i+start].getDx(); y+= frameTransformationResult[i+start].getDy(); a+= frameTransformationResult[i+start].getDa(); double xDist = pathWithWindow.get(i).getDx() - x; double yDist = pathWithWindow.get(i).getDy() - y; double aDist = pathWithWindow.get(i).getDa() - a; double dx = frameTransformationResult[i+start].getDx() + xDist; double dy = frameTransformationResult[i+start].getDy() + yDist; double da = frameTransformationResult[i+start].getDa() + aDist; newFrameTransformation.add(new FrameTransformation(dx, dy, da)); } FrameTransformation[] result = new FrameTransformation[newFrameTransformation.size()]; for(int i = 0 ;i != result.length; i++){ result[i] = newFrameTransformation.get(i); } return result; } public double[] getEvaluateMotionResult() { // EvaluateMotion evaluateMotion = new EvaluateMotionByFramePredict(15, // 15, 5, 5); EvaluateMotion evaluateMotion = new EvaluateMotionByCompareAverageValueInBlock( 15, 15, 500); double[] result = new double[bufferedImgs.length]; result[0] = 0; for (int i = 1; i < bufferedImgs.length; i++) { BufferedImage temp, temp2; synchronized (locks[i-1]) { temp = bufferedImgs[i-1]; } synchronized (locks[i]) {
  • 8. temp2 = bufferedImgs[i]; } result[i] = evaluateMotion.evaluateMotionBetweenImage( temp, temp2); } double temp = 0; for (int i = 0; i < bufferedImgs.length; i+= frameRate) { for(int j = 0; j != frameRate; j++){ if(temp < result[i+j]){ temp= result[i+j]; } } for(int j = 0; j != frameRate; j++){ result[i+j] = temp; } } return result; } // public BufferedImage readRightImg(){ // // } public BufferedImage getFirstImage() { BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); InputStream is = null; File file = new File(this.filename); try { is = new FileInputStream(file); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } // long len = file.length(); long len = width * height * 3; bufferedImgs = new BufferedImage[(int) (file.length() / len)]; byte[] bytes = new byte[(int) len]; int offset = 0; int numRead = 0; try { while (offset < bytes.length && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) { offset += numRead; } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } int ind = 0; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) {
  • 9. byte a = 0; byte r = bytes[ind]; byte g = bytes[ind + height * width]; byte b = bytes[ind + height * width * 2]; int pix = 0xff000000 | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff); // int pix = ((a << 24) + (r << 16) + (g << 8) + b); img.setRGB(x, y, pix); ind++; } } try { is.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return img; } public void allFrames(String filename) { try { File file = new File(filename); InputStream is = new FileInputStream(file); allFrames(is); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public boolean isFinished(){ return finished; } public void allFrames(InputStream is) { try { for (int i = 0; i < bufferedImgs.length; i++) { synchronized (locks[i]) { if (bufferedImgs[i] == null) { BufferedImage temp = readNextFrame(is); bufferedImgs[i] = temp; loadedFrame = i; } } } } catch (IOException e) { e.printStackTrace(); } finally { } } public BufferedImage readNextFrame(InputStream is) throws IOException {
  • 10. BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // long len = file.length(); long len = width * height * 3; byte[] bytes = new byte[(int) len]; int offset = 0; int numRead = 0; while (offset < bytes.length && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) { offset += numRead; } int ind = 0; if (findNextScene) { SceneFrameCounter = 0; // System.out.println("findNextScene" + findNextScene); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { byte a = 0; byte r = bytes[ind]; byte g = bytes[ind + height * width]; byte b = bytes[ind + height * width * 2]; // peter int red = r; if (r < 0) red = red + 256; int green = g; if (g < 0) green = green + 256; int blue = b; if (b < 0) blue = blue + 256; r = (byte) red; g = (byte) green; b = (byte) blue; nextHistogram[red / 64][green / 64][blue / 64]++; int pix = 0xff000000 | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff); // int pix = ((a << 24) + (r << 16) + (g << 8) + b); img.setRGB(x, y, pix); ind++; } } for (int i = 0; i < histogram.length; i++) for (int j = 0; j < histogram[i].length; j++) for (int p = 0; p < histogram[i][j].length; p++) { senceDiff = Math.abs(histogram[i][j][p] - nextHistogram[i][j][p]); } if (senceDiff >= senceThreshold) { findNextScene = false; for (int i = 0; i < histogram.length; i++) for (int j = 0; j < histogram[i].length; j++)
  • 11. for (int p = 0; p < histogram[i][j].length; p++) { histogram[i][j][p] = nextHistogram[i] [j][p]; } senceChangeIndex++; senceChangeFrame[senceChangeIndex] = numOfFrame; } senceDiff = 0; } else { for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { byte a = 0; byte r = bytes[ind]; byte g = bytes[ind + height * width]; byte b = bytes[ind + height * width * 2]; // peter if (SceneFrameCounter >= frameRate * secForScene) { int red = r; if (r < 0) red = red + 256; int green = g; if (g < 0) green = green + 256; int blue = b; if (b < 0) blue = blue + 256; r = (byte) red; g = (byte) green; b = (byte) blue; histogram[red / 64][green / 64][blue / 64]+ +; findNextScene = true; } // peter // for(int i = 0; i < histogram.length; i++) // for(int j = 0; j < histogram[i].length; j++) // for(int p = 0; p < histogram[i][j].length; p++) { // // } int pix = 0xff000000 | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff); // int pix = ((a << 24) + (r << 16) + (g << 8) + b); img.setRGB(x, y, pix); ind++; } } sumFrame[sumIndex] = numOfFrame; sumIndex++; SceneFrameCounter++; // System.out.println(SceneFrameCounter); }
  • 12. numOfFrame++; return img; } public BufferedImage getImg(int order) { if (order >= bufferedImgs.length) { return null; } synchronized (locks[order]) { return bufferedImgs[order]; } } public BufferedImage getCurrentImg() { if (this.processFinished == false) { return null; } synchronized (currentLock) { if (current >= bufferedImgs.length) { this.finished = true; return null; } synchronized (locks[current]) { if (last == current) { return null; } else { last = current; return bufferedImgs[current]; // return adjustedImages[current]; } } } } public BufferedImage getCurrentImgScenery() { synchronized (currentLock) { if (current >= bufferedImgs.length) { return null; } synchronized (locks[current]) { if (last == current) { return null; } else { last = current; return bufferedImgs[sumFrame[current]]; } } } } public void start() { PlayImage.this.current = 0; if (updateFrameTimerTask != null) { updateFrameTimerTask.cancel(); } java.util.Timer updateFrameTimer = new java.util.Timer(); updateFrameTimerTask = new TimerTask() { public void run() {
  • 13. synchronized (PlayImage.this.currentLock) { // System.out.printf("%d: PlayImagen",PlayImage.this.current); PlayImage.this.current++; } } }; System.out.println("start"); updateFrameTimer.scheduleAtFixedRate(updateFrameTimerTask, 0, PlayImage.this.intervalTime); } public void pause() { if (updateFrameTimerTask != null) { updateFrameTimerTask.cancel(); } } public void startOrContinue() { if (updateFrameTimerTask == null) { this.start(); } else { this.avContinue(); } } public void avContinue() { java.util.Timer updateFrameTimer = new java.util.Timer(); updateFrameTimerTask = new TimerTask() { public void run() { synchronized (PlayImage.this.currentLock) { PlayImage.this.current++; } } }; updateFrameTimer.scheduleAtFixedRate(updateFrameTimerTask, 0, PlayImage.this.intervalTime); } }