Skip to content

Commit

Permalink
updated getting started, and make sure all referenced code compiles, …
Browse files Browse the repository at this point in the history
…will add these to CI later
  • Loading branch information
liuliu committed Dec 22, 2014
1 parent 5502171 commit 831e7cb
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 35 deletions.
6 changes: 3 additions & 3 deletions site/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ highlighter: null
markdown: kramdown

kramdown:
use_coderay: true
coderay:
coderay_css: class
syntax_highligher: coderay

code_dir: _source

# Themes are encouraged to use these universal variables
# so be sure to set them if your theme uses them.
Expand Down
2 changes: 1 addition & 1 deletion site/_layouts/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
layout: default
---
<h1>{{ page.title }}</h1>
{{ page.content | markdownify }}
{{ content | markdownify }}
<h3><a href="/">&lsaquo;&nbsp;&nbsp;back&nbsp;</a></h3>
<div id="disqus_thread"></div>
<script type="text/javascript">
Expand Down
2 changes: 1 addition & 1 deletion site/_layouts/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
---
<h1>{{ page.title }}</h1>
<p>{{ page.date | date_to_human_string }}</p>
{{ page.content | markdownify }}
{{ content | markdownify }}
<h3><a href="/">&lsaquo;&nbsp;&nbsp;back&nbsp;</a></h3>
<div id="disqus_thread"></div>
<script type="text/javascript">
Expand Down
67 changes: 67 additions & 0 deletions site/_plugins/include_code.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Title: Include Code Tag for Jekyll
# Author: Brandon Mathis http://brandonmathis.com
# Description: Import files on your filesystem into any blog post as embedded code snippets with syntax highlighting and a download link.
# Configuration: You can set default import path in _config.yml (defaults to code_dir: downloads/code)
#
# Syntax {% include_code path/to/file %}
#
# Example 1:
# {% include_code javascripts/test.js %}
#
# This will import test.js from source/downloads/code/javascripts/test.js
# and output the contents in a syntax highlighted code block inside a figure,
# with a figcaption listing the file name and download link
#
# Example 2:
# You can also include an optional title for the <figcaption>
#
# {% include_code Example 2 javascripts/test.js %}
#
# will output a figcaption with the title: Example 2 (test.js)
#

require 'pathname'
require 'coderay'

module Jekyll

class IncludeCodeTag < Liquid::Tag
def initialize(tag_name, markup, tokens)
@title = nil
@file = nil
if markup.strip =~ /\s*lang:(\S+)/i
@filetype = $1
markup = markup.strip.sub(/lang:\S+/i,'')
end
if markup.strip =~ /(.*)?(\s+|^)(\/*\S+)/i
@title = $1 || nil
@file = $3
end
super
end

def render(context)
code_dir = context.registers[:site].config['code_dir'].sub(/^\//,'')
code_path = (Pathname.new(context.registers[:site].source) + code_dir).expand_path
file = code_path + @file

if File.symlink?(code_path)
return "Code directory '#{code_path}' cannot be a symlink"
end

unless file.file?
return "File #{file} could not be found"
end

Dir.chdir(code_path) do
code = file.read
@filetype = file.extname.sub('.','') if @filetype.nil?
source = CodeRay.scan(code, @filetype).div(:line_numbers => :inline, :css => :class)
return source
end
end
end

end

Liquid::Template.register_tag('include_code', Jekyll::IncludeCodeTag)
21 changes: 21 additions & 0 deletions site/_source/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
include ../../lib/config.mk

#CC += -faddress-sanitizer -fno-omit-frame-pointer
LDFLAGS := -L"../../lib" -lccv $(LDFLAGS)
CFLAGS := -O3 -Wall -I"../../lib" $(CFLAGS)

TARGETS = section-001-001 section-001-002

all: libccv.a $(TARGETS)

clean:
${MAKE} clean -C ../../lib ; rm -f *.o $(TARGETS)

$(TARGETS): %: %.o libccv.a
$(CC) -o $@ $< $(LDFLAGS)

libccv.a:
${MAKE} -C ../../lib

%.o: %.c ../lib/ccv.h
$(CC) $< -o $@ -c $(CFLAGS)
9 changes: 9 additions & 0 deletions site/_source/section-001-001.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <ccv.h>

int main(int argc, char** argv)
{
ccv_dense_matrix_t* image = 0;
ccv_read(argv[1], &image, CCV_IO_GRAY | CCV_IO_ANY_FILE);
ccv_write(image, argv[2], 0, CCV_IO_PNG_FILE, 0);
return 0;
}
19 changes: 19 additions & 0 deletions site/_source/section-001-002.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <ccv.h>

int main(int argc, char** argv)
{
ccv_dense_matrix_t* image = 0;
ccv_read(argv[1], &image, CCV_IO_GRAY | CCV_IO_ANY_FILE);
ccv_bbf_classifier_cascade_t* cascade = ccv_bbf_read_classifier_cascade(argv[2]);
ccv_array_t* faces = ccv_bbf_detect_objects(image, &cascade, 1, ccv_bbf_default_params);
int i;
for (i = 0; i < faces->rnum; i++)
{
ccv_comp_t* face = (ccv_comp_t*)ccv_array_get(faces, i);
printf("%d %d %d %d\n", face->rect.x, face->rect.y, face->rect.width, face->rect.height);
}
ccv_array_free(faces);
ccv_bbf_classifier_cascade_free(cascade);
ccv_matrix_free(image);
return 0;
}
3 changes: 2 additions & 1 deletion site/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

all: site

# This makes sure all example code compiles with latest ccv
site: doc
jekyll build
make -C _source && jekyll build

doc:
cd .. && doxygen .doxygen.conf && cd site && ./_doxygen.sh
Expand Down
32 changes: 3 additions & 29 deletions site/tutorial/index.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,14 @@ For old-schooler, run `./configure && make` in `/lib` directory will generate `l

That it. The only magic sauce is `~/ccv/lib/.deps`, which gives you all the dependencies you have to link to when you compile ccv the first time. If your ccv compiled with no dependency, it is empty (and ccv works with zero dependency).

*Remember to checkout `./serve/makefile` to see how a real-world program that uses ccv organizes.*
**Remember to checkout `./serve/makefile` to see how a real-world program that uses ccv organizes.**

Read a Photo
------------

Let's start with something small.

#include <ccv.h>
int main(int argc, char** argv)
{
ccv_dense_matrix_t* image = 0;
ccv_read(argv[1], &image, CCV_IO_GRAY | CCV_IO_ANY_FILE);
ccv_write(image, argv[2], 0, CCV_IO_PNG_FILE, 0);
return 0;
}
{:lang="c"}
{% include_code section-001-001.c %}

If your ccv build has dependency on libjpeg or libpng, the code above is sufficient to load any JPEG or PNG file into memory and save a grayscale version to the disk.

Expand All @@ -38,24 +30,6 @@ Detect a Face

Yes, knowing how to read a photo is sufficient to write an application that can do, for example, face detection.

#include <ccv.h>
int main(int argc, char** argv)
{
ccv_dense_matrix_t* image = 0;
ccv_read(argv[1], &image, CCV_IO_GRAY | CCV_IO_ANY_FILE);
ccv_bbf_classifier_cascade_t* cascade = ccv_bbf_read_classifier_cascade(argv[2]);
ccv_array_t* faces = ccv_bbf_detect_objects(image, &cascade, 1, ccv_bbf_default_params);
int i;
for (i = 0; i < faces->rnum; i++)
{
ccv_comp_t* face = (ccv_comp_t*)ccv_array_get(faces, i);
printf("%d %d %d %d\n", face->rect.x, face->rect.y, face->rect.width, face->rect.height);
}
ccv_array_free(faces);
ccv_bbf_classifier_cascade_free(cascade);
ccv_matrix_free(image);
return 0;
}
{:lang="c"}
{% include_code section-001-002.c %}

That's it.

0 comments on commit 831e7cb

Please sign in to comment.