// Line Detection by Hough Line Transform
// http://opencvexamples.blogspot.com/2013/10/line-detection-by-hough-line-transform.html
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>
#include <sys/time.h>
#define HIST
using namespace cv;
using namespace std;
int main(int argc, char *argv[])
{
Mat src;
if (argc >= 1){
src = imread(argv[1]);
} else {
printf("Usage : HoughLine_example <read_file_name>\n");
exit(1);
}
Mat dst, cdst;
Mat src_g;
struct timeval start_time, end_time;
gettimeofday(&start_time, NULL);
cvtColor(src, src_g, CV_BGR2GRAY);
#ifdef HIST
Mat eqst;
equalizeHist(src_g, eqst);
Canny(eqst, dst, 150, 250, 3); // for equalizeHist
#else
//Canny(src_g, dst, 50, 200, 3); // Normal
Canny(src_g, dst, 200, 300, 3); // Normal2
#endif
//gettimeofday(&end_time, NULL);
cvtColor(dst, cdst, CV_GRAY2BGR);
vector<Vec2f> lines;
// detect lines
HoughLines(dst, lines, 1, CV_PI/180, 150, 0, 0);
gettimeofday(&end_time, NULL);
// draw lines
for( size_t i = 0; i < lines.size(); i++ )
{
float rho = lines[i][0], theta = lines[i][1];
Point pt1, pt2;
double a = cos(theta), b = sin(theta);
double x0 = a*rho, y0 = b*rho;
pt1.x = cvRound(x0 + 1000*(-b));
pt1.y = cvRound(y0 + 1000*(a));
pt2.x = cvRound(x0 - 1000*(-b));
pt2.y = cvRound(y0 - 1000*(a));
line( cdst, pt1, pt2, Scalar(0,0,255), 3, CV_AA);
}
if (end_time.tv_usec < start_time.tv_usec) {
printf("total time = %ld.%06ld sec\n", end_time.tv_sec - start_time.tv_sec - 1, 1000000 + end_time.tv_usec - start_time.tv_usec);
}
else {
printf("total time = %ld.%06ld sec\n", end_time.tv_sec - start_time.tv_sec, end_time.tv_usec - start_time.tv_usec);
}
#ifdef HIST
imshow("equalizeHist", eqst);
#endif
imshow("Canny", dst);
imshow("source", src);
imshow("detected lines", cdst);
waitKey();
waitKey();
waitKey();
waitKey();
return 0;
}
// Line Detection by Hough Line Transform
// http://opencvexamples.blogspot.com/2013/10/line-detection-by-hough-line-transform.html
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>
#include <sys/time.h>
#define HIST
using namespace cv;
using namespace std;
int main(int argc, char *argv[])
{
Mat src;
if (argc >= 1){
src = imread(argv[1], 0);
} else {
printf("Usage : HoughLine_example <read_file_name>\n");
exit(1);
}
Mat dst, cdst;
struct timeval start_time, end_time;
gettimeofday(&start_time, NULL);
#ifdef HIST
Mat eqst;
equalizeHist(src, eqst);
Canny(eqst, dst, 150, 250, 3); // for equalizeHist
#else
Canny(src, dst, 50, 200, 3); // Normal
//Canny(src, dst, 200, 300, 3); // Normal2
#endif
cvtColor(dst, cdst, CV_GRAY2BGR);
vector<Vec2f> lines;
// detect lines
HoughLines(dst, lines, 1, CV_PI/180, 150, 0, 0);
gettimeofday(&end_time, NULL);
// draw lines
for( size_t i = 0; i < lines.size(); i++ )
{
float rho = lines[i][0], theta = lines[i][1];
Point pt1, pt2;
double a = cos(theta), b = sin(theta);
double x0 = a*rho, y0 = b*rho;
pt1.x = cvRound(x0 + 1000*(-b));
pt1.y = cvRound(y0 + 1000*(a));
pt2.x = cvRound(x0 - 1000*(-b));
pt2.y = cvRound(y0 - 1000*(a));
line( cdst, pt1, pt2, Scalar(0,0,255), 3, CV_AA);
}
if (end_time.tv_usec < start_time.tv_usec) {
printf("total time = %ld.%06ld sec\n", end_time.tv_sec - start_time.tv_sec - 1, 1000000 + end_time.tv_usec - start_time.tv_usec);
}
else {
printf("total time = %ld.%06ld sec\n", end_time.tv_sec - start_time.tv_sec, end_time.tv_usec - start_time.tv_usec);
}
#ifdef HIST
imshow("equalizeHist", eqst);
#endif
imshow("Canny", dst);
imshow("source", src);
imshow("detected lines", cdst);
waitKey();
waitKey();
waitKey();
waitKey();
waitKey();
return 0;
}
Please contact MYIR after you placed the order and kindly provide us your detailed shipping address and contact phone number for shipment. Thank you!
RGB_IMAGE src(rows, cols);
RGBSINGLE_IMAGE src_bw(rows, cols);
RGBSINGLE_IMAGE src_blur(rows, cols);
RGBSINGLE_IMAGE src1(rows, cols);
RGBSINGLE_IMAGE src2(rows, cols);
RGBSINGLE_IMAGE sobel_gx_g(rows, cols);
RGBSINGLE_IMAGE sobel_gy_g(rows, cols);
RGB_IMAGE sobel_gx(rows, cols);
RGB_IMAGE sobel_gy(rows, cols);
RGB_IMAGE_16 grad_gd(rows, cols);
RGB_IMAGE suppressed(rows, cols);
RGB_IMAGE canny_edges(rows, cols);
を行って、”HLS_8UC1”に変換し、5x5 のガウシアンフィルタを行い、Sobel フィルタ処理が終了した後で、hls::CvtColor<HLS_RGB2GRAY>( src, src_bw );
を行い、”HLS_8UC3”に戻している。hls::CvtColor
( sobel_gx_g, sobel_gx );
hls::CvtColor( sobel_gy_g, sobel_gy );
を使用して C コードの合成を行った。結果を示す。hls::GaussianBlur<5,5>( src_bw, src_blur );
// Canny_fiter_tb.cpp
// 2016/05/20 by marsee
// OpenCV 2 の Mat を使用したバージョン
//
#include <iostream>
#include "hls_opencv.h"
#include "Canny_filter.h"
using namespace cv;
void canny_filter(AXI_STREAM& input, AXI_STREAM& output, int rows, int cols, int threshold_low, int threshold_high);
void opencv_canny_filter(Mat& src, Mat& dst, int threshold_low, int threshold_high, int sobel_size);
int main (int argc, char** argv) {
//const int threshold_low = 50;
//const int threshold_high = 200;
const int threshold_low = 20;
const int threshold_high = 30;
const int sobel_size = 3;
// OpenCV で 画像を読み込む
Mat src = imread(INPUT_IMAGE);
AXI_STREAM src_axi, dst_axi;
// Mat フォーマットから AXI4 Stream へ変換
cvMat2AXIvideo(src, src_axi);
// image_filter() 関数をコール
canny_filter(src_axi, dst_axi, src.rows, src.cols, threshold_low, threshold_high);
// AXI4 Stream から Mat フォーマットへ変換
// dst は宣言時にサイズとカラー・フォーマットを定義する必要がある
Mat dst(src.rows, src.cols, CV_8UC3);
AXIvideo2cvMat(dst_axi, dst);
// Mat フォーマットからファイルに書き込み
imwrite(OUTPUT_IMAGE, dst);
// opencv_image_filter() をコール
Mat dst_cv(src.rows, src.cols, CV_8UC3);
opencv_canny_filter(src, dst_cv, 50, 200, sobel_size);
imwrite(OUTPUT_IMAGE_GOLDEN, dst_cv);
// dst と dst_cv が同じ画像かどうか?比較する
for (int y=0; y<src.rows; y++){
Vec3b* dst_ptr = dst.ptr<Vec3b>(y);
Vec3b* dst_cv_ptr = dst_cv.ptr<Vec3b>(y);
for (int x=0; x<src.cols; x++){
Vec3b dst_bgr = dst_ptr[x];
Vec3b dst_cv_bgr = dst_cv_ptr[x];
// bgr のどれかが間違っていたらエラー
if (dst_bgr[0] != dst_cv_bgr[0] || dst_bgr[1] != dst_cv_bgr[1] || dst_bgr[2] != dst_cv_bgr[2]){
printf("x = %d, y = %d, Error dst=%d,%d,%d dst_cv=%d,%d,%d\n", x, y,
dst_bgr[0], dst_bgr[1], dst_bgr[0], dst_cv_bgr[0], dst_cv_bgr[1], dst_cv_bgr[2]);
//return 1;
}
}
}
printf("Test with 0 errors.\n");
return 0;
}
void opencv_canny_filter(Mat& src, Mat& dst, int threshold_low, int threshold_high, int sobel_size){
Canny(src, dst, (double)threshold_low, (double)threshold_high, sobel_size);
}
だ。hls::GaussianBlur<5,5>( src_bw, src_blur, 1.4, 1.4 );
にした。つまり line[500] から line[50] に変更した。この値は、合成時に効いてくるようだ。リソース使用量が増えてしまうし、合成時のメモリ使用量が極端に増えてしまう。hls::Polar_< ap_fixed<16,3>, ap_fixed<12,12> >lines[50];
hls::GaussianBlur<5,5>()
hls::Sobel<1,0,3>()
hls::Sobel<0,1,3>()
gradient_decomposition( sobel_gx, sobel_gy, grad_gd ),
nonmax_suppression()
hysteresis()
// Line Detection by Hough Line TransformのC++コードを使用させて頂いて、変更を加えています
// http://opencvexamples.blogspot.com/2013/10/line-detection-by-hough-line-transform.html
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#define HIST
using namespace cv;
using namespace std;
int main()
{
Mat src = imread("test_1080p_rb3.bmp", 0);
Mat dst, cdst;
#ifdef HIST
Mat eqst;
equalizeHist(src, eqst); // ヒストグラム平均化
imshow("equalizeHist", eqst);
Canny(eqst, dst, 150, 250, 3); // for equalizeHist
#else
Canny(src, dst, 50, 200, 3); // Normal
#endif
imshow("Canny", dst);
cvtColor(dst, cdst, CV_GRAY2BGR);
vector<Vec2f> lines;
// detect lines
HoughLines(dst, lines, 1, CV_PI/180, 150, 0, 0);
// draw lines
for( size_t i = 0; i < lines.size(); i++ )
{
float rho = lines[i][0], theta = lines[i][1];
Point pt1, pt2;
double a = cos(theta), b = sin(theta);
double x0 = a*rho, y0 = b*rho;
pt1.x = cvRound(x0 + 1000*(-b));
pt1.y = cvRound(y0 + 1000*(a));
pt2.x = cvRound(x0 - 1000*(-b));
pt2.y = cvRound(y0 - 1000*(a));
line( cdst, pt1, pt2, Scalar(0,0,255), 3, CV_AA);
}
imshow("source", src);
imshow("detected lines", cdst);
waitKey();
return 0;
}
1.RGBからグレーへの変換
2.画像ヒストグラムのイコライゼーション
3.エッジ検出
4.ハフ変換
44a00000
0000008B
44a0005c
00000000
44a00060
00000000
44a00064
00000000
44a00058
00000c80
44a00054
00000c80
44a00050
00000258
44a00030
00000003
44a000ac
00000000
44a000B0
00000000
44a000B4
00000000
44a000a8
00000c80
44a000a4
00000c80
44a000a0
00000258
44a20040
00000000
44a20044
80000000
44a20000
00000002
44a10040
00000000
44a10000
00000002
44a40000
00000000
44a40004
00000000
40000000
00000001
ffffffff
// cam_disp_axis.c
// 2015/06/14 by marsee
// 2016/05/06 : Supporting to the MM2S of AXI VDMA
//
// Refered to Xilinx\SDK\2015.1\data\embeddedsw\XilinxProcessorIPLib\drivers\axivdma_v5_1\doc\html\api
// Refered to https://github.com/elitezhe/Atyls-VDMA-one-in-one-out/blob/master/SDK/colorbar/src/helloworld.c
// Refered to http://www.xilinx.com/support/documentation/ip_documentation/axi_vdma/v6_2/pg020_axi_vdma.pdf
// Refered to http://forums.xilinx.com/t5/Embedded-Processor-System-Design/Axi-VDMA-on-Digilent-Atlys/td-p/297019/page/2
// Refered to https://forums.xilinx.com/xlnx/attachments/xlnx/zaps/5096/1/helloworld.c
//
// normal camera out
//
#include <stdio.h>
#include <stdlib.h>
#include "xaxivdma.h"
#include "xil_io.h"
#include "xparameters.h"
#include "sleep.h"
#define NUMBER_OF_WRITE_FRAMES 3 // Note: If not at least 3 or more, the image is not displayed in succession.
#define HORIZONTAL_PIXELS 800
#define VERTICAL_LINES 600
#define PIXEL_NUM_OF_BYTES 4
#define FRAME_BUFFER_ADDRESS 0x10000000
static XAxiVdma_DmaSetup Vdma0_WriteCfg, Vdma0_ReadCfg;
void cam_i2c_init(volatile unsigned *mt9d111_i2c_axi_lites) {
mt9d111_i2c_axi_lites[64] = 0x2; // reset tx fifo ,address is 0x100, i2c_control_reg
mt9d111_i2c_axi_lites[64] = 0x1; // enable i2c
}
void cam_i2x_write_sync(void) {
// unsigned c;
// c = *cam_i2c_rx_fifo;
// while ((c & 0x84) != 0x80)
// c = *cam_i2c_rx_fifo; // No Bus Busy and TX_FIFO_Empty = 1
usleep(1000);
}
void cam_i2c_write(volatile unsigned *mt9d111_i2c_axi_lites, unsigned int device_addr, unsigned int write_addr, unsigned int write_data){
mt9d111_i2c_axi_lites[66] = 0x100 | (device_addr & 0xfe); // Slave IIC Write Address, address is 0x108, i2c_tx_fifo
mt9d111_i2c_axi_lites[66] = write_addr;
mt9d111_i2c_axi_lites[66] = (write_data >> 8)|0xff; // first data
mt9d111_i2c_axi_lites[66] = 0x200 | (write_data & 0xff); // second data
cam_i2x_write_sync();
}
int main(){
// malloc frame buffer
// unsigned int *frame_buffer = (unsigned int *)malloc(HORIZONTAL_PIXELS * VERTICAL_LINES * PIXEL_NUM_OF_BYTES * NUMBER_OF_WRITE_FRAMES);
// AXI VDMA Initialization sequence
XAxiVdma_Config *XAxiVdma0_Config;
XAxiVdma XAxiVdma0;
int XAxiVdma0_Status;
XAxiVdma0_Config = XAxiVdma_LookupConfig(XPAR_AXI_VDMA_0_DEVICE_ID); // Look up the hardware configuration for a device instance
if (XAxiVdma0_Config == NULL){
fprintf(stderr, "No AXI VDMA found\n");
return(-1);
}
XAxiVdma0_Status = XAxiVdma_CfgInitialize(&XAxiVdma0, XAxiVdma0_Config, XAxiVdma0_Config->BaseAddress); // Initialize the driver with hardware configuration
if (XAxiVdma0_Status != XST_SUCCESS){
fprintf(stderr, "XAxiVdma_CfgInitialize() failed\n");
return(-1);
}
// AXI VDMA Write Settings
XAxiVdma_Reset(&XAxiVdma0, XAXIVDMA_WRITE);
while(XAxiVdma_ResetNotDone(&XAxiVdma0, XAXIVDMA_WRITE)) ;
XAxiVdma0_Status = XAxiVdma_SetFrmStore(&XAxiVdma0, NUMBER_OF_WRITE_FRAMES, XAXIVDMA_WRITE); // Set the number of frame store buffers to use.
Vdma0_WriteCfg.VertSizeInput = VERTICAL_LINES;
Vdma0_WriteCfg.HoriSizeInput = HORIZONTAL_PIXELS * PIXEL_NUM_OF_BYTES;
Vdma0_WriteCfg.Stride = HORIZONTAL_PIXELS * PIXEL_NUM_OF_BYTES; // Indicates the number of address bytes between the first pixels of each video line.
Vdma0_WriteCfg.FrameDelay = 0; // Indicates the minimum number of frame buffers the Genlock slave is to be behind the locked master. This field is only used if the channel is enabled for Genlock Slave operations. This field has no meaning in other Genlock modes.
Vdma0_WriteCfg.EnableCircularBuf = 1; // Indicates frame buffer Circular mode or frame buffer Park mode. 1 = Circular Mode Engine continuously circles through frame buffers.
Vdma0_WriteCfg.EnableSync = 0; // Enables Genlock or Dynamic Genlock Synchronization. 0 = Genlock or Dynamic Genlock Synchronization disabled.
Vdma0_WriteCfg.PointNum = 0; // No Gen-Lock
Vdma0_WriteCfg.EnableFrameCounter = 0; // Endless transfers
Vdma0_WriteCfg.FixedFrameStoreAddr = 0; // We are not doing parking
XAxiVdma0_Status = XAxiVdma_DmaConfig(&XAxiVdma0, XAXIVDMA_WRITE, &Vdma0_WriteCfg);
if (XAxiVdma0_Status != XST_SUCCESS){
fprintf(stderr, "XAxiVdma_DmaConfig() failed (XAXIVDMA_WRITE)\n");
return(-1);
}
// AXI VDMA Read Settings
XAxiVdma_Reset(&XAxiVdma0, XAXIVDMA_READ);
while(XAxiVdma_ResetNotDone(&XAxiVdma0, XAXIVDMA_READ)) ;
XAxiVdma0_Status = XAxiVdma_SetFrmStore(&XAxiVdma0, NUMBER_OF_WRITE_FRAMES, XAXIVDMA_READ); // Set the number of frame store buffers to use.
Vdma0_ReadCfg.VertSizeInput = VERTICAL_LINES;
Vdma0_ReadCfg.HoriSizeInput = HORIZONTAL_PIXELS * PIXEL_NUM_OF_BYTES;
Vdma0_ReadCfg.Stride = HORIZONTAL_PIXELS * PIXEL_NUM_OF_BYTES; // Indicates the number of address bytes between the first pixels of each video line.
Vdma0_ReadCfg.FrameDelay = 0; // Indicates the minimum number of frame buffers the Genlock slave is to be behind the locked master. This field is only used if the channel is enabled for Genlock Slave operations. This field has no meaning in other Genlock modes.
Vdma0_ReadCfg.EnableCircularBuf = 1; // Indicates frame buffer Circular mode or frame buffer Park mode. 1 = Circular Mode Engine continuously circles through frame buffers.
Vdma0_ReadCfg.EnableSync = 0; // Enables Genlock or Dynamic Genlock Synchronization. 0 = Genlock or Dynamic Genlock Synchronization disabled.
Vdma0_ReadCfg.PointNum = 0; // No Gen-Lock
Vdma0_ReadCfg.EnableFrameCounter = 0; // Endless transfers
Vdma0_ReadCfg.FixedFrameStoreAddr = 0; // We are not doing parking
XAxiVdma0_Status = XAxiVdma_DmaConfig(&XAxiVdma0, XAXIVDMA_READ, &Vdma0_ReadCfg);
if (XAxiVdma0_Status != XST_SUCCESS){
fprintf(stderr, "XAxiVdma_DmaConfig() failed (XAXIVDMA_READ)\n");
return(-1);
}
// Frame buffer address set
unsigned int frame_addr = (unsigned int)FRAME_BUFFER_ADDRESS;
int i;
for (i=0; i<NUMBER_OF_WRITE_FRAMES; i++){
Vdma0_WriteCfg.FrameStoreStartAddr[i] = frame_addr;
Vdma0_ReadCfg.FrameStoreStartAddr[i] = frame_addr;
frame_addr += HORIZONTAL_PIXELS * PIXEL_NUM_OF_BYTES * VERTICAL_LINES;
}
XAxiVdma0_Status = XAxiVdma_DmaSetBufferAddr(&XAxiVdma0, XAXIVDMA_WRITE, Vdma0_WriteCfg.FrameStoreStartAddr);
if (XAxiVdma0_Status != XST_SUCCESS){
fprintf(stderr, "XAxiVdma_DmaSetBufferAddr() failed (XAXIVDMA_WRITE)\n");
return(-1);
}
XAxiVdma0_Status = XAxiVdma_DmaSetBufferAddr(&XAxiVdma0, XAXIVDMA_READ, Vdma0_ReadCfg.FrameStoreStartAddr);
if (XAxiVdma0_Status != XST_SUCCESS){
fprintf(stderr, "XAxiVdma_DmaSetBufferAddr() failed (XAXIVDMA_READ)\n");
return(-1);
}
// axis_switch_1, 1to2 ,Select M00_AXIS
// Refer to http://marsee101.blog19.fc2.com/blog-entry-3177.html
Xil_Out32((XPAR_CAMERA_MODULE_AXIS_SWITCH_1_BASEADDR+0x40), 0x0);
Xil_Out32((XPAR_CAMERA_MODULE_AXIS_SWITCH_1_BASEADDR+0x44), 0x80000000); // disable
Xil_Out32((XPAR_CAMERA_MODULE_AXIS_SWITCH_1_BASEADDR), 0x2); // Commit registers
// axis_switch_0, 2to1, Select S00_AXIS
// Refer to http://marsee101.blog19.fc2.com/blog-entry-3177.html
Xil_Out32((XPAR_CAMERA_MODULE_AXIS_SWITCH_1_DEVICE_ID+0x40), 0x0);
Xil_Out32((XPAR_CAMERA_MODULE_AXIS_SWITCH_1_DEVICE_ID), 0x2); // Commit registers
// VDMA start
XAxiVdma0_Status = XAxiVdma_DmaStart(&XAxiVdma0, XAXIVDMA_WRITE);
if (XAxiVdma0_Status != XST_SUCCESS){
fprintf(stderr, "XAxiVdma_DmaStart() failed (XAXIVDMA_WRITE)\n");
return(-1);
}
XAxiVdma0_Status = XAxiVdma_DmaStart(&XAxiVdma0, XAXIVDMA_READ);
if (XAxiVdma0_Status != XST_SUCCESS){
fprintf(stderr, "XAxiVdma_DmaStart() failed (XAXIVDMA_READ)\n");
return(-1);
}
// mt9d111_inf_axis_0, axi_iic_0
volatile unsigned int *mt9d111_axi_lites;
volatile unsigned int *mt9d111_i2c_axi_lites;
mt9d111_axi_lites = (volatile unsigned *)XPAR_CAMERA_MODULE_MT9D111_INF_AXIS_0_BASEADDR;
mt9d111_i2c_axi_lites = (volatile unsigned *)XPAR_CAMERA_MODULE_AXI_IIC_0_BASEADDR;
mt9d111_axi_lites[0] = (volatile unsigned int)FRAME_BUFFER_ADDRESS; // Camera Interface start (Address is dummy)
// CMOS Camera initialize, MT9D111
cam_i2c_init(mt9d111_i2c_axi_lites);
cam_i2c_write(mt9d111_i2c_axi_lites, 0xba, 0xf0, 0x1); // Changed regster map to IFP page 1
cam_i2c_write(mt9d111_i2c_axi_lites, 0xba, 0x97, 0x20); // RGB Mode, RGB565
mt9d111_axi_lites[1] = 0; // One_shot_mode is disabled
return(0);
}
44a00000
0000008B
44a0005c
00000000
44a00060
00000000
44a00064
00000000
44a00058
00000c80
44a00054
00000c80
44a00050
00000258
44a00030
00000003
44a000ac
00000000
44a000B0
00000000
44a000B4
00000000
44a000a8
00000c80
44a000a4
00000c80
44a000a0
00000258
44a20040
00000000
44a20044
80000000
44a20000
00000002
44a10040
00000000
44a10000
00000002
44a40000
00000000
44a40004
00000000
ffffffff
日 | 月 | 火 | 水 | 木 | 金 | 土 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 | - | - | - | - |