element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
FPGA
  • Technologies
  • More
FPGA
Forum Help Object detection and tracking with color space conversion and morph operators
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join FPGA to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 1 reply
  • Subscribers 548 subscribers
  • Views 466 views
  • Users 0 members are here
  • video
  • image proccesing
  • zynq
  • fpga
  • high level synthesis
  • hls
  • xili
Related

Help Object detection and tracking with color space conversion and morph operators

brhn
brhn 10 months ago
Help Object detection and tracking with color space conversion and morph operators

I want to implement with boundingbox the opencv example code on the link:

 

https://www.opencv-srf.com/2010/09/object-detection-using-color-seperation.html

 

I need to conversion XF_8UC1 to XF_8UC3 to hsv2rgb

 

and I also get hanging error in the for loop and xf::cv::boundingbox:

pixel = imgOutput.read_float(i);

#include "xf_colordetect_config.h"

static constexpr int __XF_DEPTH = (HEIGHT * WIDTH * (XF_PIXELWIDTH(IN_TYPE, NPC1)) / 8) / (INPUT_PTR_WIDTH / 8);
static constexpr int __XF_DEPTH_OUT = (HEIGHT * WIDTH * (XF_PIXELWIDTH(OUT_TYPE, NPC1)) / 8) / (OUTPUT_PTR_WIDTH / 8);
static constexpr int __XF_DEPTH_FILTER = (FILTER_SIZE * FILTER_SIZE);

void colordetect_accel(ap_uint<INPUT_PTR_WIDTH>* img_in,
                       ap_uint<OUTPUT_PTR_WIDTH>* img_out,
                       int rows,
                       int cols) {
    #pragma HLS INTERFACE m_axi port=img_in offset=slave bundle=gmem0 depth=__XF_DEPTH
    #pragma HLS INTERFACE m_axi port=img_out offset=slave bundle=gmem4 depth=__XF_DEPTH_OUT
    #pragma HLS INTERFACE s_axilite port=rows
    #pragma HLS INTERFACE s_axilite port=cols
    #pragma HLS INTERFACE s_axilite port=return

    // Initialize input and intermediary matrices
    xf::cv::Mat<IN_TYPE, HEIGHT, WIDTH, NPC1, XF_CV_DEPTH_IN_1> imgInput(rows, cols);
    xf::cv::Mat<IN_TYPE, HEIGHT, WIDTH, NPC1, XF_CV_DEPTH_RGB2HSV> rgb2hsv(rows, cols);
    xf::cv::Mat<OUT_TYPE, HEIGHT, WIDTH, NPC1, XF_CV_DEPTH_HELP_1> imgHelper1(rows, cols);
    xf::cv::Mat<OUT_TYPE, HEIGHT, WIDTH, NPC1, XF_CV_DEPTH_HELP_2> imgHelper2(rows, cols);
    xf::cv::Mat<OUT_TYPE, HEIGHT, WIDTH, NPC1, XF_CV_DEPTH_HELP_3> imgHelper3(rows, cols);
    xf::cv::Mat<OUT_TYPE, HEIGHT, WIDTH, NPC1, XF_CV_DEPTH_HELP_3> imgHelper4(rows, cols);
    xf::cv::Mat<OUT_TYPE, HEIGHT, WIDTH, NPC1, XF_CV_DEPTH_HELP_3> imgHelper5(rows, cols);
    xf::cv::Mat<OUT_TYPE, HEIGHT, WIDTH, NPC1, XF_CV_DEPTH_OUT_1> imgOutput(rows, cols);
    xf::cv::Mat<OUT_TYPE, HEIGHT, WIDTH, NPC1, XF_CV_DEPTH_OUT_1> imgOutputwithBox(rows, cols);

    unsigned char low_thresh[MAXCOLORS] = {170, 150, 60};
    unsigned char high_thresh[MAXCOLORS] = {179, 255, 255};
    unsigned char _kernel[FILTER_SIZE * FILTER_SIZE] = {1, 1, 1, 1, 1, 1, 1, 1, 1}; // 3x3 kernel for erosion/dilation

    // Load input image to xf::cv::Mat format
    xf::cv::Array2xfMat<INPUT_PTR_WIDTH, IN_TYPE, HEIGHT, WIDTH, NPC1, XF_CV_DEPTH_IN_1>(img_in, imgInput);

    // RGB to HSV conversion
    xf::cv::bgr2hsv<IN_TYPE, HEIGHT, WIDTH, NPC1, XF_CV_DEPTH_IN_1, XF_CV_DEPTH_RGB2HSV>(imgInput, rgb2hsv);

    // Color thresholding to detect specific colors
    xf::cv::colorthresholding<IN_TYPE, OUT_TYPE, MAXCOLORS, HEIGHT, WIDTH, NPC1, XF_CV_DEPTH_RGB2HSV,
                              XF_CV_DEPTH_HELP_1>(rgb2hsv, imgHelper1, low_thresh, high_thresh);

    // Apply morphological operations (erode + dilate)
    xf::cv::erode<XF_BORDER_CONSTANT, OUT_TYPE, HEIGHT, WIDTH, XF_KERNEL_SHAPE, FILTER_SIZE, FILTER_SIZE, ITERATIONS,
                  NPC1, XF_CV_DEPTH_HELP_1, XF_CV_DEPTH_HELP_2>(imgHelper1, imgHelper2, _kernel);
    xf::cv::dilate<XF_BORDER_CONSTANT, OUT_TYPE, HEIGHT, WIDTH, XF_KERNEL_SHAPE, FILTER_SIZE, FILTER_SIZE, ITERATIONS,
                   NPC1, XF_CV_DEPTH_HELP_2, XF_CV_DEPTH_HELP_3>(imgHelper2, imgHelper3, _kernel);

    xf::cv::dilate<XF_BORDER_CONSTANT, OUT_TYPE, HEIGHT, WIDTH, XF_KERNEL_SHAPE, FILTER_SIZE, FILTER_SIZE, ITERATIONS,
                          NPC1, XF_CV_DEPTH_HELP_2, XF_CV_DEPTH_HELP_3>(imgHelper3, imgHelper4, _kernel);
    xf::cv::erode<XF_BORDER_CONSTANT, OUT_TYPE, HEIGHT, WIDTH, XF_KERNEL_SHAPE, FILTER_SIZE, FILTER_SIZE, ITERATIONS,
                     NPC1, XF_CV_DEPTH_HELP_1, XF_CV_DEPTH_HELP_2>(imgHelper4, imgOutput, _kernel);

    xf::cv::hsv2rgb<XF_8UC1, XF_8UC1, HEIGHT, WIDTH, NPC1, XF_CV_DEPTH_IN_1, XF_CV_DEPTH_IN_1>(imgOutput, imgOutputwithBox);

    // Calculate bounding box by iterating through imgThresholded
    //int min_x = cols, min_y = rows, max_x = 0, max_y = 0;

	/*for (int i = 0; i < rows; i++) {
		for (int j = 0; j < cols; j++) {
				unsigned char pixel;
				pixel = imgOutput.read_float(i);
				if (pixel > 0) { // If pixel is part of the detected region
				// Update bounding box coordinates
				if (j < min_x) min_x = j;
				if (j > max_x) max_x = j;
				if (i < min_y) min_y = i;
				if (i > max_y) max_y = i;
			}
		}
	}*/


	// Define the bounding box region as an xf::cv::Rect object
	/*xf::cv::Rect_<int> roi;
	roi.x = min_x;
	roi.y = min_y;
	roi.width = max_x - min_x + 1;
	roi.height = max_y - min_y + 1;*/

	// Define the bounding box color (e.g., green)
	//xf::cv::Scalar<4, unsigned char> color(0, 255, 0, 255); // RGBA format, green color

    // Draw bounding box on the thresholded image
    //xf::cv::boundingbox<OUT_TYPE, HEIGHT, WIDTH, 1, NPC1, XF_CV_DEPTH_HELP_1>(imgOutput, &roi, &color, 1);

    // Step 5: Convert processed data to output array
    xf::cv::xfMat2Array<OUTPUT_PTR_WIDTH, OUT_TYPE, HEIGHT, WIDTH, NPC1, XF_CV_DEPTH_OUT_1>(imgOutput, img_out);
}

  • Sign in to reply
  • Cancel

Top Replies

  • brhn
    brhn 6 months ago +1
    Thank you mates, I solved.
  • brhn
    brhn 6 months ago

    Thank you mates, I solved.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube