Git Product home page Git Product logo

Comments (4)

ermig1979 avatar ermig1979 commented on May 18, 2024

Could you write a code that you use to perform detection? I have tried to detect objects when the image dimensions are not multiple of 16, but the algorithm works fine. So I think that you could incorrect use Simd::Detection.

from simd.

pallegd avatar pallegd commented on May 18, 2024

This is pretty much it:

#include "simd/src/Simd/SimdDetection.hpp"
#include "simd/src/Simd/SimdDrawing.hpp"

typedef Simd::DetectionSimd::Allocator Detection;
// set to false for no debug output
bool debug_active = false;

void Debug(const char *s)
{
if (debug_active)
{
printf("%s\n", s);
}
}

extern "C" long InitDetection(char *detectionPath, int pictureWidth, int pictureHeight)
{
// create detection object
Detection *detection = new Detection();

// attempt to load detection
if (detection->Load(detectionPath))
{
    // load of detection ok, create size object
    Detection::Size size;
Detection::Size size_min;
    size.x = pictureWidth;
    size.y = pictureHeight;
    if (detection->Init(size))
    {
        // all ok, return pointer to created detection object
        return (long) detection;
    }
    else
    {
        Debug("InitDetection: Failed to init detection.");
    }
}
else
{
    Debug("InitDetection: Failed to load detection.");
}

// load of detection failed
// remove detection, and return 0
delete detection;
return 0;

}

extern "C" int CloseDetection(long detectionObject)
{

extern "C" int CalcDetection(long detectionObject, int pictureWidth, int pictureHeight, void* pictureData, int* results)
{
// get detection object
Detection detection = (Detection) detectionObject;

// return -1 if Detect fails
int found = -1;

// clear results
memset(results, -1, 4 * MAX_RESULTS * sizeof(int));

// create view object from image data
Detection::View *image = new Detection::View(pictureWidth, pictureHeight, Detection::View::Format::Gray8, pictureData, 16);

Detection::Objects objects;
if (detection->Detect(*image, objects))
{
    Debug("CalcDetection: Detect returned ok.");

	// set number of objects found
	found = objects.size();

    // make results array
    for (size_t i = 0; (i < objects.size()) && (i < MAX_RESULTS); ++i)
    {
    	*results++ = objects[i].rect.left;
        *results++ = objects[i].rect.top;
        *results++ = objects[i].rect.right;
        *results++ = objects[i].rect.bottom;
    }

	// only for debug purposes
	if (debug_active)
	{
		// display number of found objects
		char s[80];
		sprintf(s, "CalcDetection: Found %i objects.", (int)objects.size());
		Debug(s);

    	// draw rectangle around hits
    	for (size_t i = 0; i < objects.size(); ++i)
    		Simd::DrawRectangle(*image, objects[i].rect, uint8_t(255));
	
		// save output
		if (image->Save("output.pgm"))
		{
			Debug("CalcDetection: Save ok.");
		}
	}
}
else
{
    Debug("CalcDetection: Failed to perform calculation.");
}

// remove view object
delete image;

// return number of objects found, -1 if error
return found;

}

from simd.

ermig1979 avatar ermig1979 commented on May 18, 2024

You have a mistake at this line:

Detection::View *image = new Detection::View(pictureWidth, pictureHeight, Detection::View::Format::Gray8, pictureData, 16);

This constructor creates a Simd::View with given alignment but original image doesn't have the same one.
Better way is using another constructor to create Simd::View:

Detection::View *image = new Detection::View(pictureWidth, pictureHeight, pictureWidth, Detection::View::Format::Gray8, pictureData);

from simd.

pallegd avatar pallegd commented on May 18, 2024

Thank, this solves my problem, closing the issue.

from simd.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.