Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Ldpe2G committed May 19, 2016
1 parent ea0dfd0 commit ba2b101
Show file tree
Hide file tree
Showing 28 changed files with 771 additions and 0 deletions.
22 changes: 22 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
lazy val commonSettings = Seq(
version := "0.1.0",
scalaVersion := "2.11.7"
)

lazy val root = (project in file(".")).
settings(commonSettings: _*).
settings(
name := "pencil_style_scala"
)


libraryDependencies ++= Seq(
"org.scalanlp" %% "breeze" % "0.12",
"org.scalanlp" %% "breeze-natives" % "0.12",
"org.scalanlp" %% "breeze-viz" % "0.12"
)

resolvers ++= Seq(
"Sonatype Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/",
"Sonatype Releases" at "https://oss.sonatype.org/content/repositories/releases/"
)
Binary file added images/img/IMG_4343.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/img/b.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/img/banana.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/img/boat1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/img/boat2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/img/c.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/img/f.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/img/flower.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/img/golden_gate.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/img/h.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/img/hoovertowernight.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/img/people2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/img/people3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/img/poples.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/img/sign.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/img/tubingen.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/textures/a.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/textures/d.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/textures/texture.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/opencv-300.jar
Binary file not shown.
2 changes: 2 additions & 0 deletions project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sbt.version=0.13.11

2 changes: 2 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "4.0.0")

30 changes: 30 additions & 0 deletions python/solve.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from scipy.sparse import lil_matrix
from scipy.sparse.linalg import spsolve
import os


A = lil_matrix((10, 10))
b = lil_matrix((10, 10))

for line in open( os.getcwd() + '/python/' + 'AA.txt','r').readlines():
lists = line.split()
if len(lists) == 2:
A = lil_matrix( ( int(lists[0]), int(lists[1]) ) )
else:
A[int(lists[0]), int(lists[1])] = float(lists[2])

for line in open( os.getcwd() + '/python/' + 'bb.txt','r').readlines():
lists = line.split()
if len(lists) == 2:
b = lil_matrix( ( int(lists[0]), int(lists[1]) ) )
else:
b[int(lists[0]), int(lists[1])] = float(lists[2])

A = A.tocsr()
x = spsolve(A, b)

fo = open( os.getcwd() + '/python/' + 'xx.txt', 'wb')
for xx in x:
fo.write( str(xx) + '\n' );

fo.close()
66 changes: 66 additions & 0 deletions run_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
ROOT=$(cd "$(dirname $0)"; pwd)

# better to copy your opencv-300.jar to replace this one
OPENCV_JAR_FILE=$ROOT/lib/opencv-300.jar

# needs to set to your opencv-3.0 build lib path
LIBRARY_PATH=$HOME/opencv3.0/opencv-3.0.0/build/lib/

CLASS_PATH=$OPENCV_JAR_FILE:$ROOT/target/scala-2.11/classes/:$HOME/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.11.7.jar:\
$HOME/.ivy2/cache/org.scalanlp/breeze_2.11/jars/breeze_2.11-0.12.jar:\
$HOME/.ivy2/cache/org.scalanlp/breeze-macros_2.11/jars/breeze-macros_2.11-0.12.jar:\
$HOME/.ivy2/cache/com.github.fommil.netlib/core/jars/core-1.1.2.jar:\
$HOME/.ivy2/cache/net.sourceforge.f2j/arpack_combined_all/jars/arpack_combined_all-0.1.jar:\
$HOME/.ivy2/cache/net.sf.opencsv/opencsv/jars/opencsv-2.3.jar:\
$HOME/.ivy2/cache/com.github.rwl/jtransforms/jars/jtransforms-2.4.0.jar:\
$HOME/.ivy2/cache/junit/junit/jars/junit-4.8.2.jar:\
$HOME/.ivy2/cache/org.apache.commons/commons-math3/jars/commons-math3-3.2.jar:\
$HOME/.ivy2/cache/org.spire-math/spire_2.11/jars/spire_2.11-0.7.4.jar:\
$HOME/.ivy2/cache/org.spire-math/spire-macros_2.11/jars/spire-macros_2.11-0.7.4.jar:\
$HOME/.ivy2/cache/org.slf4j/slf4j-api/jars/slf4j-api-1.7.5.jar:\
$HOME/.ivy2/cache/com.chuusai/shapeless_2.11/bundles/shapeless_2.11-2.0.0.jar:\
$HOME/.ivy2/cache/org.scalanlp/breeze-natives_2.11/jars/breeze-natives_2.11-0.12.jar:\
$HOME/.ivy2/cache/com.github.fommil.netlib/netlib-native_ref-osx-x86_64/jars/netlib-native_ref-osx-x86_64-1.1-natives.jar:\
$HOME/.ivy2/cache/com.github.fommil.netlib/native_ref-java/jars/native_ref-java-1.1.jar:\
$HOME/.ivy2/cache/com.github.fommil/jniloader/jars/jniloader-1.1.jar:\
$HOME/.ivy2/cache/com.github.fommil.netlib/netlib-native_ref-linux-x86_64/jars/netlib-native_ref-linux-x86_64-1.1-natives.jar:\
$HOME/.ivy2/cache/com.github.fommil.netlib/netlib-native_ref-linux-i686/jars/netlib-native_ref-linux-i686-1.1-natives.jar:\
$HOME/.ivy2/cache/com.github.fommil.netlib/netlib-native_ref-win-x86_64/jars/netlib-native_ref-win-x86_64-1.1-natives.jar:\
$HOME/.ivy2/cache/com.github.fommil.netlib/netlib-native_ref-win-i686/jars/netlib-native_ref-win-i686-1.1-natives.jar:\
$HOME/.ivy2/cache/com.github.fommil.netlib/netlib-native_ref-linux-armhf/jars/netlib-native_ref-linux-armhf-1.1-natives.jar:\
$HOME/.ivy2/cache/com.github.fommil.netlib/netlib-native_system-osx-x86_64/jars/netlib-native_system-osx-x86_64-1.1-natives.jar:\
$HOME/.ivy2/cache/com.github.fommil.netlib/native_system-java/jars/native_system-java-1.1.jar:\
$HOME/.ivy2/cache/com.github.fommil.netlib/netlib-native_system-linux-x86_64/jars/netlib-native_system-linux-x86_64-1.1-natives.jar:\
$HOME/.ivy2/cache/com.github.fommil.netlib/netlib-native_system-linux-i686/jars/netlib-native_system-linux-i686-1.1-natives.jar:\
$HOME/.ivy2/cache/com.github.fommil.netlib/netlib-native_system-linux-armhf/jars/netlib-native_system-linux-armhf-1.1-natives.jar:\
$HOME/.ivy2/cache/com.github.fommil.netlib/netlib-native_system-win-x86_64/jars/netlib-native_system-win-x86_64-1.1-natives.jar:\
$HOME/.ivy2/cache/com.github.fommil.netlib/netlib-native_system-win-i686/jars/netlib-native_system-win-i686-1.1-natives.jar:\
$HOME/.ivy2/cache/org.scalanlp/breeze-viz_2.11/jars/breeze-viz_2.11-0.12.jar:\
$HOME/.ivy2/cache/jfree/jcommon/jars/jcommon-1.0.16.jar:\
$HOME/.ivy2/cache/jfree/jfreechart/jars/jfreechart-1.0.13.jar:\
$HOME/.ivy2/cache/org.apache.xmlgraphics/xmlgraphics-commons/jars/xmlgraphics-commons-1.3.1.jar:\
$HOME/.ivy2/cache/commons-io/commons-io/jars/commons-io-1.3.1.jar:\
$HOME/.ivy2/cache/commons-logging/commons-logging/jars/commons-logging-1.0.4.jar:\
$HOME/.ivy2/cache/com.lowagie/itext/jars/itext-2.1.5.jar:\
$HOME/.ivy2/cache/bouncycastle/bcmail-jdk14/jars/bcmail-jdk14-138.jar:\
$HOME/.ivy2/cache/bouncycastle/bcprov-jdk14/jars/bcprov-jdk14-138.jar

PYTHON_DIR_PATH=$ROOT/python

IMG_PATH=$ROOT/images/img/flower.png
OUT_PATH=$ROOT/images/pencil_result.jpg
TEXTURE_IMG_PATH=$ROOT/images/textures/texture.jpg

# set to 0 generates the pencil drawing,
# set to 1 generates the colourful pencil drawing
IS_DRAW_COLOR=1

# set to 1 will output the middle results
# set to 0 just output the final result
IS_SHOW_STEP=1



java -Xmx4G -cp $CLASS_PATH \
-Djava.library.path=$LIBRARY_PATH \
PencilStyle $IMG_PATH $OUT_PATH $TEXTURE_IMG_PATH $IS_DRAW_COLOR $PYTHON_DIR_PATH $IS_SHOW_STEP
34 changes: 34 additions & 0 deletions src/main/scala/PencilStyle.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import org.opencv.core.Core
import Utils._
import java.io.InputStreamReader
import java.io.BufferedReader

object PencilStyle {

def main(args: Array[String]): Unit = {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME)
if(args.length < 6) {
println("usage: PencilStyle imagePath resultPath textureImgPath isDrawColor pythonDirPath isShowSteps")
}
val img = imgRead(args(0))

val (showStep, outputPath) = if (args(5).toInt == 1) (true, args(1).substring(0, args(1).lastIndexOf("/"))) else (false, "")

val cons = Configs(
30, // larger for a shorter line fragment
8, // smaller for thiner outline sketches
2f, //larger for smoother tonal mappings
0.2f,
args(2),
args(4),
showStep,
outputPath
)
val result = {
if (args(3).toInt == 0) pencilDraw(img, cons)
else colourPencilDraw(img, cons)
}
imgWrite(result, args(1))
}

}
15 changes: 15 additions & 0 deletions src/main/scala/test.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import org.opencv.core.Core

object test {

def run() = {

}

def main(args: Array[String]): Unit = {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME)
println("Hello, OpenCV")
// Load the native library.
}

}
Loading

0 comments on commit ba2b101

Please sign in to comment.